It's something that seemed up in the air less than 24 hours before the vote, unlikely just a few months ago and completely unfathomable despite bold claims to the contrary midway through President Donald Trump's first year in office.

Yet the Republican-controlled US Senate, by a vote of 51-49, early Saturday morning passed a historic overhaul of the US tax code, clearing what has long been considered the largest and most byzantine hurdle in an effort that hasn't been completed in more than 31 years.

"We have an opportunity now to make America more competitive, and to keep jobs from being shipped offshore and provide substantial relief to the middle class," McConnell told reporters after the vote. "At the end, there was not a single Democrat who thought this was a good idea, and so we're going to take this message to the American people a year from now."

Trump sounded a jubilant note Saturday morning, thanking Republican lawmakers on Twitter for their work on the bill.

Biggest Tax Bill and Tax Cuts in history just passed in the Senate. Now these great Republicans will be going for final passage. Thank you to House and Senate Republicans for your hard work and commitment!

The White House, too, lauded passage of the legislation Saturday morning, saying in a statement that the senators who voted for the bill "did a great service to their constituents" and adding that the legislation would lead to "sustainable economic prosperity and job creation."

"We have a once-in-a-lifetime opportunity to reclaim America's great destiny," the statement read, adding that the administration looked forward to enacting the legislation by year's end.

The legislative product -- something that will touch every facet of American life, every US business and every individual in the country -- came from a year of closed-door, cloistered meetings. It was driven by GOP goals of significant cuts and benefits to corporate entities designed to turbocharge economic growth, with significantly less benefit to the individuals who have been at the heart of the Republican pitch for the plan itself. It was created without the inclusion of Democrats and it came on the heels of a devastating failure on what has been the Republican Party's top legislative priority for more than seven years: the repeal of Obamacare. Just hours before the bill was voted on, aides were still writing the bill. When the final bill emerged, notes were still hand-written and scribbled in the margins.

Yet, McConnell lost just one Republican vote, something even senior GOP members would deem almost inconceivable just a few weeks ago. After rushing the bill through a release and a markup, GOP leaders also survived a late, and completely unexpected, scare that nearly stalled a tax bill on the brink of passage. The bill is now expected to go to conference committee with House.

The story of how Senate Republicans closed the deal, which despite the roaring success of Republicans up to this point, still faces challenges in the days ahead as lawmakers in both chambers attempt to reconcile proposals that differ sharply in several key substantive ways, involves multiple Republican senators negotiating with other members right up until the final moments before the vote.

To tell that story, CNN spoke with dozens of lawmakers, administration officials, aides and lobbyists directly involved in the process, most of whom requested anonymity to candidly discuss the process.

The speed with which GOP leaders recovered from Thursday night's scare on the bill was emblematic of the entire process. Expectations of potential doom from the lobbyists and outside advocates who watched the process like hawks quickly were overcome by the phoenix-like nature of a legislative priority that for decades has flummoxed both parties. As the proposal took another step forward, Republicans were candid about what appeared to be the accelerant behind the effort: political imperative. The idea that passing something -- anything -- was better than protecting a single provision or a single industry.

McConnell's work for months, Corker unswayed

How the bill survived started at the top with McConnell.

After a tumultuous August in which Trump chastised the Senate leader frequently on Twitter for failing to deliver the votes on repealing Obamacare, McConnell kept his powder dry. In speeches across Kentucky, McConnell didn't disparage Trump and returned to Washington ready to work with a partner whose style was the antithesis of McConnell's say-less, focus-more approach.

Senate Majority Leader Mitch McConnell, a Kentucky Republican

A source familiar with their discussions told CNN that after a meeting shortly after Labor Day, Trump and McConnell began speaking at a clip more frequent then at any other point in Trump's presidency.

"Daily," the source told CNN.

The two men divided and conquered, with McConnell asking Trump explicitly for help trying to convince Sen. Ron Johnson of Wisconsin and Kentucky Sen. Rand Paul to vote for the tax bill.

Eventually it was just Sen. Bob Corker, a Republican from Tennessee who won't seek re-election in 2018 and has often sparred with Trump, who voted against the proposal, citing concerns that the bill would add too much to the country's deficit. Corker had made his support contingent on leaders including a trigger in the bill that would generate automatic tax cuts in the event the tax bill didn't get the anticipated growth. But after reworking the proposal several times, the Senate parliamentarian ruled that the trigger wouldn't pass Senate rules that allowed Republicans to pass their tax bill along a party-line vote. Corker then demanded $350 billion in additional cuts his colleagues weren't ready to give him.

But even Corker, who had left aides and colleagues fuming Thursday night with a dramatic showing on the Senate floor that included him huddled around the Senate's parliamentarian and GOP leaders for more than hour, offered conciliatory remarks Friday morning at a closed-door GOP conference meeting.

Sen. Bob Corker speaks to reporters on Capitol Hill May 10, 2017 in Washington, DC.

According to two GOP sources, Corker moved to de-escalate the situation that angered his colleagues Thursday night, saying he was happy the party was on the precipice of passing their tax bill even if he wasn't going to be with them. Republican leaders as of Friday morning were still trying to win his support, but sources acknowledged the reality: the decision had been made to cut him loose. They had the votes without him.

"This is yet another tough vote," Corker said in a statement Friday. "I am disappointed. I wanted to get to yes. But at the end of the day, I am not able to cast aside my fiscal concerns and vote for legislation that I believe, based on the information I currently have, could deepen the debt burden on future generations."

Everyone besides Corker got in line

Earlier Friday morning, Sens. Steve Daines of Montana and Johnson had announced their support for the tax bill after leadership promised they'd include a provision in the tax bill that increased the tax break for pass-through entities from 17.4% to 23%.

Johnson's conversion to a "yes" vote on the bill was perhaps the most hard-fought -- and frustrating -- for Republican leaders. For weeks he'd expressed discontent about being left out of the process. He didn't just want to address the pass-through issue, he wanted to overhaul the Republican approach to it altogether. At one point, he appeared willing to stall the bill out in committee just to prove his point.

Sen. Ron Johnson, a Wisconsin Republican, is seen in July 2016.

It was the President himself -- someone regularly maligned by Republican senators and staff alike -- who helped bring Johnson along, multiple aides and administration officials said. It was in an exchange, shortly before the committee vote in a closed-door meeting of Republican senators and Trump, where Johnson vented his frustrations in front of everyone. Trump listened, engaged occasionally, dismissed once ("Oh c'mon, Ron," Trump said at one point, according to two people in the room) and didn't take personally an unusual slight: Johnson declined to stand when addressing Trump in the meeting, breaking bipartisan tradition. When Johnson finished, Trump said bluntly: "That's not a reason to vote against the bill, Ron."

But it was another part of the exchange that others said added clarity to what would eventually occur: Johnson complained nobody ever listened him. Trump countered that he did. And he was right. Trump administration officials, and the President himself, had been working with Johnson behind the scenes for days. And he had help from inside the Republican conference. Sen. David Perdue, a freshman senator from Georgia and former CEO, was also reaching out to Johnson -- by phone over the Thanksgiving break, at another point on the Senate floor. He reported back to the President -- with whom he's formed a close relationship over the course of the year -- giving him another source on where Johnson really stood on the proposal.

What Johnson wanted, however, hadn't yet come the night before the final vote: a more generous expansion of the pass-through tax rate cut than Republican leaders were willing to offer to get he and Daines on board. He would get it by the next morning.

Leadership also won over Sen. Susan Collins of Maine -- a senator who helped kill the GOP's Obamacare repeal efforts and who many considered out of reach on the tax bill. But several aides say Collins, unlike health care, made clear to McConnell she wanted to get to "yes" on the tax legislation. The two had several private meetings. She made her concerns known -- and the specific things she would need to come along, including the inclusion of the state and local tax deduction for property taxes, capped at $10,000, which had previously been repealed in the bill. Republican leaders, including the President at the closed-door conference meeting, solidified her support by giving her assurances that they'd push for an Obamacare market stabilization bill in upcoming weeks.

Sen. Susan Collins, a Maine Republican

"Having secured these key improvements in the bill, as well as the commitments to legislation to help lower health insurance premiums, I will cast my vote in support of the Senate tax reform bill," Collins said in a lengthy statement before the final vote.

A final boost for GOP leaders: Sen. Jeff Flake, who like Corker had been pushing hard for the deficit "trigger" idea. He too would come on board, even without the trigger, when his concerns over the sunset of the expensing provision in the bill were addressed. He was also given assurances by Vice President Mike Pence that he would be involved in the negotiations over how to handle a solution for halting the Deferred Action for Childhood Arrivals program, which Trump pledged to end by March.

Victory after repeated defeats against Obamacare

The success of 11th-hour horse-trading represents a massive win for McConnell, who spent months haunted by the conference's inability to repeal and replace Obamacare in July.

After 11 months, Senate Republicans finally delivered on a core election promise.

For their part, Senate Democrats were unified in their opposition -- and their disdain for the proposal. They took to the floor, member after member, for three days -- attacking the proposal for being too weighted toward corporate interests, fiscally irresponsible and produced through a process that was equal parts scattershot and secretive. Sen. Richard Durbin, an Illinois Democrat, waved a page of a draft version of the proposal with handwritten changes to in the margins at one point to demonstrate what he attacked as a haphazard process. Others seized on the bill's $1.5 trillion price tag -- and the lack fo any nonpartisan analysis that said the growth created by the proposal could cover that cost, as Republicans had pledged.

"My Republican friends will ultimately pay the consequences for this bill in 2018 and beyond. The Republican Party will never again be the party of tax cuts for the middle class," Sen. Chuck Schumer, the Senate' Minority Leader, said on the Senate floor Friday evening.

The victory on tax reform also represented a first step on dismantling Obamacare as well. On Friday, Senate Republicans managed to not only pass a tax reform bill, but also to deliver a first and crucial blow to the Affordable Care Act. The tax bill repealed the individual mandate, a provision that required individuals to purchase health care or face a fine, something that just four months proved too complicated for the conference.

In a way, including the provision -- which was the ultimate gamble for a conference that failed repeatedly to repeal it just months before -- represented a double win for the party. Finally, Republican senators have done what their House colleagues and even their donors feared they couldn't: they've finally passed a cornerstone piece of legislation.

Four senators and a bill one year in the making

While Republicans had worked on various proposals to overhaul the tax code for decades, Republican senators began strategizing their latest attempt to reform the tax code not long after Trump stunned the country and won the White House. Republicans had a President ready and willing to sign a bill if they could manage to send him one.

According to a source familiar with the tax negotiations, as far back as December 2016, a small group of Republican senators -- all on the Senate Finance Committee and guided by Chairman Orrin Hatch and his staff -- began hashing out the Senate's course.

Sen. Tim Scott, a South Carolina Republican

The group included Sens. Rob Portman, formally the director of the Office of Management and Budget, Sen. John Thune, a member of the GOP leadership, Pat Toomey, a fiscal conservative and a member of the Senate's Budget Committee and Sen. Tim Scott, a rising conservative star in the party. Over the next several months, the senators held what the source said must have been hundreds of meetings as they sought to find a way forward not only among fellow senators but in cooperation with the House of Representatives and Trump -- who lawmakers widely acknowledge was more engaged and interested in tax reform than he had been on health care.

"There's been an enormous amount of work done. The reason you see everybody looking so tired is because we are," said Sen. John Kennedy, a Louisiana Republican. "They did a great job of keeping us apprised so we wouldn't be surprised."

It was those four senators' knowledge about the bill that made the effort successful, senators said.

"The health care was sort of a committee of the whole and staff did most of the explaining," said Sen. Lamar Alexander. "In this case, you had the senators themselves more directly involved in writing and explaining and defending the bill and I think it's the principal reason why it succeeded."

"I think Sen. Toomey was born with a tax-reform bill in his bassinet, and Sen. Portman probably was too," Alexander added as he walked onto a Senate elevator.

Sen. Pat Toomey, a Pennsylvania Republican (Photo by Mark Wilson/Getty Images)

Republican senators widely credit the four senators with bringing the bill to the finish line. Sen. James Lankford, a Oklahoma Republican who desperately wanted a trigger like Corker, said he met regularly with them and that unlike on health care, where no one had ownership over the process, colleagues knew exactly who they could go to with concerns.

"Those four were really the front people who each took a section whether it be international taxes, whether it be business, whether it be individual. Each had their lane and everybody as they were going through it could run it through them," Lankford said. "I don't mean this flippantly, they all did a good job."

In the final days and hours of negotiations, sources familiar tell CNN, Portman played a critical role in helping his colleagues get comfortable with the bill. Just minutes before the Republican conference meeting Friday morning that would determine the fate of the bill, Portman could be seen standing outside the Strom Thurmond room in the Capitol for 10 minutes with Collins and the Senate's Majority Whip John Cornyn. The source familiar with the negotiation said that in the final three days, Portman met with Daines and Corker and dined for breakfast with Collins Wednesday just two days before the crucial vote.

In the end, Republicans filled the chamber, anticipating the final vote. They slapped backs and shook hands. McConnell winked and pointed at the Vice President Mike Pence, who presided over the vote, a sign of relief after months of searching for that one legislative achievement.

Democrats one by one voted and left, a protest to the process they abhorred. In the end their side of the chamber was empty and the vote tally was called: "51 to 49," the clerk read.

But in his news conference following the vote, McConnell dismissed Democrats' concerns, saying "You complain about process when you're losing."