Doug Jones’s odds-defying victory in Alabama — handing Democrats a vanishingly rare Senate win in the Deep South — scrambles President Trump’s legislative agenda for the coming year, threatens to heighten Republican infighting and sounds an alarm for the GOP’s prospects in November’s midterm elections.

Any dent in the two-seat advantage Republicans hold in the Senate would carry major governing consequences, but the loss of what had been considered one of the party’s safest seats carries a special sting for the GOP.

One consequence is Democrats’ much more plausible path to the Senate majority next year. The 2018 map was widely seen to favor Republicans, with 10 Democrats seeking reelection in states President Trump won last year and only two Republican seats clearly at risk.

Now, if Democratic incumbents can survive in Indiana, Missouri, North Dakota, West Virginia and elsewhere in what is shaping up to be a favorable environment, GOP losses in Arizona and Nevada could allow Charles E. Schumer (D-N.Y.) to unseat Mitch McConnell (R-Ky.) as Senate majority leader.

Some Republicans view the Alabama seat once held by Attorney General Jeff Sessions as the first casualty in an internecine GOP battle that has pitted establishment Republicans personified by McConnell against populist insurgents led by former White House strategist Stephen K. Bannon.

“It should be a hurricane siren for every Republican,” said Josh Holmes, a former top aide to McConnell. “This is what the death of a party looks like, and without an immediate course correction and rejection of the Steve Bannon view of the world, you can lose races in states like Alabama.”

Jones’s victory over Roy Moore, who was dogged by allegations of sexual misconduct, comes after an improbable series of decisions and revelations that together put the GOP’s grasp on the seat at risk — starting with Trump’s decision to tap Sessions, one of his most loyal campaign supporters, for a key Cabinet position.

Scandal-tarred Gov. Robert Bentley (R) filled the vacancy in the interim with Luther Strange, the state attorney general who was investigating Bentley. That appearance of an unseemly bargain gave an opening to Moore, the former chief justice of the Alabama Supreme Court whose defiant antics had twice resulted in his removal from office but won him a fervent following among Alabama conservatives.

With Bannon's backing, Moore overcame not only Strange's establishment support but also Trump's intervention to emerge from the Republican primary and face Jones on Tuesday. But in November, the race was upended when The Washington Post published the account of a woman who accused Moore of having propositioned and groped her when she was 14 and he was in his 30s.

More accusations of misconduct followed, and the former state judge faced the desertion of national Republican support and a pressure campaign led by McConnell to force him to end his campaign. But Moore instead turned the tables, casting the attacks as an effort by Washington elites and out-of-town media outlets to drive him from the race.

Jones, meanwhile, spent November and much of early December watching as Republicans — including the state's GOP senior senator, Richard C. Shelby — abandoned Moore while national Democrats and grass-roots donors rallied on his own behalf, giving him a massive spending advantage in the race's final weeks.

Preliminary exit poll results: How different groups voted in Alabama

If there is any solace for Republicans, it is in the path not taken: Had Moore won, he would have joined the Senate under an unprecedented cloud that would itself have distracted from the GOP’s legislative agenda.

Moore faced the prospect of an immediate investigation by the Senate Ethics Committee into the allegations that he sexually harassed and in some cases abused teenage girls three decades ago. Even a swift-moving probe, by Senate standards, would have lasted months, and Moore’s dealings with his colleagues would have been fraught, to say the least.

Many of his potential fellow Republican senators, led by McConnell, called on Moore to drop out of the race. One, Jeff Flake of Arizona, went so far as to donate to Jones. In the days before the election, many Republican senators refused to even speculate about a Moore victory.

“My hope is that the people of Alabama don’t send him here,” Sen. Lisa Murkowski (R-Alaska) said before polls closed Tuesday.

But neither a lack of collegiality nor an ethics probe would have prevented Moore from casting votes on the Senate floor for Republican bills. While there was some question about how reliable Moore’s support might have been for GOP priorities, there is no expectation that Jones will be in the habit of taking cues from Republican leaders.

In the immediate aftermath of Jones’s victory late Tuesday, Moore’s Republican critics unloaded on Bannon. “This is a brutal reminder that candidate quality matters regardless of where you are running,” said Steven Law, president and chief executive of the Senate Leadership Fund, a well-funded super PAC tied to McConnell. “Not only did Steve Bannon cost us a critical Senate seat in one of the most Republican states in the country, but he also dragged the president of the United States into his fiasco.”

Bannon, for his part, as recently as Monday fingered the party elite for undermining Moore.

“What they’re doing is trying to shut up President Trump and Judge Moore,” he said. “They would rather see Roy Moore beaten tomorrow, you know that.”

While Congress remains on track to clear a sweeping tax bill before Jones arrives, any hiccup could suddenly throw the GOP plan to deliver $1.5 trillion in tax cuts into question. And other big potential Republican priorities for 2018 — including potential bills to boost infrastructure spending and cut back on entitlement programs — are now in limbo as every last vote comes under the election-year spotlight.

Barring a new effort at bipartisan dealmaking that has been largely absent so far under the Trump administration, the GOP appears on track to head into the November midterms with only one major accomplishment to tout: a tax-cut bill that has polled poorly and delivers most of its direct benefit to corporations and the wealthy.

Democratic congressional leaders are under tremendous pressure from their party’s left flank to resist Trump at every juncture. And ahead of Tuesday’s results, moderate Democrats said they were not especially hopeful that a surprise Jones victory would spur a new atmosphere of bipartisanship.

"I'm not holding my breath," said Sen. Mark R. Warner (D-Va.), who added that a Jones victory on the heels of a strong Democratic showing in Virginia's state races last month "would be a message that people are rejecting the kind of venom-filled rhetoric that comes out of this White House."

The few Senate Republicans who would even contemplate serving alongside an Alabama Democrat before the returns came in were not eager to discuss what that outcome might portend. “If Mr. Jones wins, that’s going to mean Mr. Jones has gotten more votes than Mr. Moore,” said Sen. John Neely Kennedy (R-La.).

Other GOP sages, meanwhile, are left to wonder how this ever happened in the first place — and whether a reprise can be avoided.

Other primary battles await: Bannon and Trump-aligned political organs are backing populist candidates in the Arizona and Nevada primaries that party honchos in Washington fear cannot win a general election. And the shade of politics in Arizona and Nevada, they warn, is nowhere near as Republican red as Alabama crimson.

“If I had the top five Republican minds in politics and we spent three months attempting to conceive of a way to lose an Alabama Senate race, I’m not sure that we could come up with it,” Holmes said. “You could literally take any name out of a phone book except Roy Moore’s and win by double digits. And we managed to get the only guy in Alabama that could lose to a Democrat.”

Paul Kane, Michael Scherer, David Weigel and Erica Werner contributed to this report.