It was supposed to be smooth sailing for the Republican tax plan from here on out. Both the House and the Senate have passed bills that would fundamentally change the tax code for the next generation. They still have some details to hash out between them, but Congress seemed on the verge of a sweeping tax overhaul.

But then Doug Jones won a stunning victory in the Alabama Senate race.

He has opened up a very real, if still perhaps unlikely, path for the GOP’s biggest legislative priority to fail. The worst-case scenario for Republicans — and the only plausible way for opponents to stop a dramatically unpopular tax proposal — has revealed itself.

A Republican disaster begins in Alabama, where the party mostly if begrudgingly aligned itself behind Roy Moore in Tuesday’s special election despite credible allegations of sexual misconduct involving teenagers. President Trump himself made the calculation clear: They needed Moore’s vote for the tax bill.

Democrats refusal to give even one vote for massive Tax Cuts is why we need Republican Roy Moore to win in Alabama. We need his vote on stopping crime, illegal immigration, Border Wall, Military, Pro Life, V.A., Judges 2nd Amendment and more. No to Jones, a Pelosi/Schumer Puppet! — Donald J. Trump (@realDonaldTrump) December 4, 2017

But they didn’t get it. Jones stunned America with an upset victory over Moore in one of the reddest states in the country. If he reaches the Senate before Republicans pass their tax plan, it would be a huge blow to their tax reform dreams.

Senate Republicans are passing their tax bill through the budget reconciliation process, which requires only 50 votes to advance instead of the usual 60. So Republicans can afford two defections from their 52 members. If Jones were to be sworn in before the tax bill is passed, suddenly Republicans would have only one vote to spare. With Sen. Bob Corker (R-TN) seeming implacable — he was the only Republican to oppose the Senate bill the first time — they could not survive any more desertions.

But one GOP vote has been looking increasingly tenuous: Susan Collins of Maine, the most moderate Republican in the Senate. She gave her support to the tax bill, which would repeal Obamacare’s individual mandate, in part on the promise that Congress would also pass bills designed to stabilize the health care law.

Very pleased @SenateMajLdr committed to support passage of two impt bills before year's end to mitigate premium increases: Alexander-Murray proposal to help low-income families afford insurance & my bipartisan bill to protect people w/ pre-existing conditions via high-risk pools. pic.twitter.com/UmOIbd0CQn — Sen. Susan Collins (@SenatorCollins) December 2, 2017

In the past few days, House Speaker Paul Ryan has thrown cold water on those bills and the White House started to back away from its commitment. House Republicans have warned that there aren’t the votes in the lower chamber to pass the bills Collins supports.

Collins has in turn started to leave herself room to oppose the final tax plan that House and Senate negotiators are working on, if her demands are not met.

This path to failure has become clear: Jones wins in Alabama on Tuesday, the tax negotiations drag on long enough for him to be seated, and Collins flips to a “no” vote because her extracted concessions on health care fall through.

Republicans are determined to make the tax plan happen, but failure is at least plausible. They don’t want to take any chances: One tax lobbyist told me Republican leaders are aiming to introduce a final bill by the end of this week and pass it in the Senate next Monday — before Jones is expected to be seated.

So Congress is now in a race against the clock on the tax bill, trying to pass their biggest bill of the year before Doug Jones is sworn in and Susan Collins changes her mind.

A Doug Jones win might be the first step to a GOP tax implosion

This worst-case scenario begins once Jones takes office. Republicans are then down to 51 senators. Without Corker, who announced his retirement earlier this year and is against the tax plan because of its projected $1.5 trillion increase to the federal deficit, they would have just 50 votes for the tax bill. They can’t lose anyone else.

Republicans have already been trying to eliminate the Jones factor by passing their tax plan before he could even get to the Senate. Jones won’t be sworn in right away — he has to wait until state officials certify the results and that could take weeks. According to lobbyists, Republicans are trying to introduce and pass their final tax legislation through the conference committee process in the Senate as soon as this coming Monday.

But Republicans haven’t done a great job of meeting their ambitious legislative deadlines so far. They have some big problems to fix in the final bill, and every change shifts around tens of billions or hundreds of billions of dollars. It could get messy.

If the House-Senate negotiations go south and Republicans can’t pass a bill before Jones is sworn in, they would have no more margin for error. Corker is a lost cause. Jones looks unlikely to vote for the GOP tax bill, even as a comparatively conservative Democrat, citing concerns that it would direct most of its benefits to wealthy Americans at the expense of the lower and middle classes.

"What I have said all along is that I am troubled by tax breaks for the wealthy, which seem to be, in this bill, overloaded," Jones told reporters last month. "I'm troubled by what appears to be, ultimately, tax increases or no tax cuts for the middle class."

All eyes would then turn to Collins.

Susan Collins is the softest “yes” vote, and she could change her mind

Collins, who had already defied her party on Obamacare repeal earlier this year, got almost everything she wanted in exchange for her vote on the Senate tax bill. Republican leaders met her demands on the state and local tax deductions and the tax deduction for medical expenses.

But the biggest promises were about Obamacare. The Senate bill would repeal the Affordable Care Act’s individual mandate, the requirement that every American have insurance or pay penalty. The Congressional Budget Office projects that would lead to 13 million fewer Americans having health insurance and premiums increasing.

Collins is worried about those consequences and wants to mitigate them. She has demanded that as the tax bill passes, Congress also pass two bills that are designed to help stabilize the Obamacare markets without the mandate. Experts are dubious about whether the proposals are actually enough to offset the loss of the mandate, but that is the price Collins placed on her vote.

She said she got that commitment from Senate Majority Leader Mitch McConnell and from Trump, and so she voted for the Senate tax bill. But comments from Republican leaders and the White House in recent days cast doubt on whether Congress would actually follow through.

First, Ryan’s office reportedly told his colleagues that they were not a party to the deal McConnell and Trump reached with Collins. Then a White House spokesperson appeared to back away slightly from the deal last week.

“The President supports the repeal of the individual mandate,” Hogan Gidley, a deputy White House press secretary, told Bloomberg. “We have also had productive discussions with Congress about how to temporarily provide stability in the marketplace. However, we’re not going to get ahead of any negotiations until a bill is presented to us.”

So it seems unlikely Collins’s hopes for Obamacare stabilization would be met before the tax bill comes up again — and maybe not ever. Collins would certainly have the pretext to flip her vote, already devastatingly unpopular, and progressive activists are still targeting her despite her support for the original Senate bill.

Collins has left herself an opening to oppose the final tax package.

"I always wait until the final version of the bill is brought before us before I make a final decision on whether or not to support it," she said on CBS’s Face the Nation this weekend. "There are major differences between the House and Senate bills. And I don't know where the bill is going to come out."

For now, all this is speculative. Collins might be wavering, but she has been much more positive about tax reform than she was about Obamacare repeal. She might only need fig leaves to support the Republican bill.

The tax bill has so far relied on speed and the GOP’s desperate desire for a “win.” That could still carry the plan through. If Republican leaders have their way, they won’t wait around for Jones to become a senator or for Collins to have a change of heart. They’re trying to send a tax overhaul to Trump’s desk in less than a week’s time. Just in case.