John McCain stole the show this week. At 1:30 a.m. Friday, he orchestrated the finale in dramatic fashion.

In a painful setback for President Donald Trump and a devastating loss for Senate Majority Leader Mitch McConnell (R-KY), the Senate narrowly rejected an effort to advance an Obamacare repeal bill, leaving GOP leaders shocked and scrambling for a way forward on their seven-year quest to repeal and replace the 2010 law.

In a 49-51 vote, Republican leaders were unable to muster the needed votes to pass pared-down repeal legislation. McCain, who returned to Washington this week from Arizona after a brain-cancer diagnosis, cast the deciding vote in the early hours of Friday morning.

Only three Republicans voted against the bill, but that was enough to tank it. Sens. Susan Collins (R-ME), Lisa Murkowski (R-AK), and McCain joined all 46 Democrats and two independents in opposing it.

The fact that Republicans got so close to passing a scaled-back repeal was remarkable. GOP senators spent the day offering their disgust with the bill and the process for producing it—calling it, among other things, a “disaster” and a “fraud”—but nearly all of them came crawling back after vague assurances from House GOP leaders that the bill they passed would be changed when the two chambers meet to hash out their legislative differences.

None of the lawmakers inside the chamber, nor the reporters or members of the public sitting in the third-floor galleries, were sure of the outcome as roll was called. Collins and Murkowski were expected to vote against the bill. It was McCain, who, in his triumphant return to the chamber where he has served for three decades, provided the drama at the very end.

The “maverick” was skeptical of the GOP’s new plan from its inception. As he entered the Senate floor, he declined to reveal how he would vote, only telling reporters: “Wait for the show.”

McConnell’s show became McCain’s show.

As the final wrangling played out on the Senate floor in advance of the roll call, observers were engaged in strenuous body-language analysis. After chatting with McCain, Senate Majority Whip John Cornyn (R-TX) gave a thumbs down to a fellow lawmaker—signaling they might lose his vote. McCain then applauded and nodded his head after Senate Minority Leader Chuck Schumer (D-NY) urged his colleagues to vote against the bill.

Vice President Mike Pence, who was brought in to break a potential 50-50 tie, was working the floor intensely. Pence huddled with McCain, Murkowski, and Collins, seemingly in an effort to convince them to switch their votes.

Democrats huddled around Schumer as they began to realize that Senate Republicans likely didn’t have enough votes. McCain then walked over to the Democratic side to speak with Schumer, and more Democrats joined the pack.

At one point, McCain was deep in conversation with Schumer, and abruptly stopped. He put his hands out and mouthed the word “fuck!” while staring at the ceiling.

Sen. Chris Coons (D-DE), who was in that huddle, recounted to reporters how he found out about McCain’s decision.

“He stood with a group of us and said, ‘I am a no,’” Coons said, detailing his attempts to keep his emotions in check. “I was trying not to, like, jump up and down and smile. Because I thought, you never know.”

Coons credited Schumer with leading the Democrats’ efforts to sway McCain.

Ahead of the roll-call vote, the tension was evident among Republicans. Sens. Roger Wicker (R-MS), Orrin Hatch (R-UT), Pat Roberts (R-KS), and others were slumped nervously in their chairs as intense conversations were taking place at various areas of the GOP side of the chamber.

Just before 1:30 a.m., McConnell turned around and gave a thumbs up—did he have the votes after all?

He did not. McConnell went ahead with the vote knowing he had come up short.

When McCain voted “no,” Democrats applauded and cheered, to the clear dismay of their Republican colleagues. After the failed vote, McConnell admitted defeat.

“Yes, this is a disappointment. A disappointment indeed.... Our friends on the other side decided early on they didn’t want to engage with us in a serious way to help those suffering under Obamacare,” McConnell said in a speech on the Senate floor.

Many Republican senators were reluctant to speak with reporters to describe their initial reactions. Cornyn made the short walk from the Senate floor to his office in dead silence, ignoring questions from reporters.

McCain rushed out of the Capitol after the vote, with reporters frantically chasing after him. It took the 80-year-old 30 seconds to get from the Senate floor to a first-floor exit out of the Capitol.

“I thought it was the right thing to do,” he said.

Murkowski, who voted “no” with McCain, said simply: “I’m just going to allow my vote to speak for itself. But very difficult. Very difficult.”

For their colleagues who voted for the bill, “difficult” was an understatement.

“No, it was not a shock. Naturally, we’re disappointed. But each one of the members of the Senate has to make those decisions on their own. And we had hoped that, as [McCain] deliberated it, he would come to the same agreement that most of the rest of us had come to,” Sen. Mike Rounds (R-SD) told The Daily Beast, predicting further destabilization of the insurance markets under Obamacare.

Plain and simple, the GOP’s seven-year-old promise to repeal and replace Obamacare was dealt a significant—maybe even fatal—setback.

“Clearly it was a difficult promise, because the president challenged us to replace, not just repeal,” Sen. Bill Cassidy (R-LA) told reporters.

Trump, who has let congressional Republicans largely dictate the health-care overhaul process, responded on Twitter around 2:30 a.m., writing: “3 Republicans and 48 Democrats let the American people down. As I said from the beginning, let ObamaCare implode, then deal. Watch!”

The final legislative text was crafted throughout the day Thursday, but wasn’t released until three hours before the vote. Known as “skinny repeal,” the eight-page plan would have gutted much of the Affordable Care Act’s individual mandate while scrapping the employer mandate for a minimum of six years. The bill would have defunded Planned Parenthood for one year, and scrapped the tax on medical-device manufacturers for three years. Additionally, the bill would have provided more flexibility to states in setting insurance regulations.

The Congressional Budget Office said the bill would result in 16 million additional Americans being uninsured by 2026, and premiums would rise by 20 percent.

Senate Republican leaders characterized the bill as simply a mechanism to advance negotiations to a conference committee—a panel of lawmakers from the House and Senate charged with hashing out disagreements and coming up with a final product that would get an up-or-down vote in the House and Senate. Both McConnell and Cornyn acknowledged as much ahead of the vote.

“We intend to pass a bill and go to conference with the House to make this bill better,” Cornyn said on the Senate floor just past midnight.

Ahead of the final vote, however, there was no guarantee that a conference would’ve happened, even if a majority of senators had voted in favor.

Undecided Republicans were seeking assurances from House Speaker Paul Ryan (R-WI) that the bill would never pass in its current form should it get to conference committee. Sens. Lindsey Graham (R-SC), Ron Johnson (R-WI) and McCain held a press conference Thursday afternoon to declare that they would not vote in favor of the “skinny” repeal bill until they received such assurances.

Ryan released a statement Thursday night saying the House was “willing” to establish a conference, but gave no explicit promise that the House wouldn’t eventually pass the Senate bill. Ryan’s statement was enough to sway a few wary Republicans. But it wasn’t enough for McCain.

“The Speaker’s statement that the House would be ‘willing’ to go to conference does not ease my concern that this shell of a bill could be taken up and passed at any time,” McCain said in a statement released by his office. He doubled down on his calls for a return to regular order in the Senate—namely, holding hearings and involving Democrats in the process.

Senate conservatives warned against portraying Friday morning’s vote as a victory for Democrats. Sen. Ted Cruz (R-TX) told reporters that Democrats have “no interest in doing anything productive” to fix Obamacare.

“Now listen, I recognize there are going to be Democrats trumpeting tonight as a victory for a policy that is collapsing and failing the American people,” he said, adding: “I have heard no indication from even a single Democrat that they are willing to change.”

Senate Republicans’ health-care reform push relied on a process known as budget reconciliation, whereby a simple majority is needed for passage. Each iteration of their plan to repeal and replace Obamacare was written in a closed-door setting, and moderates and conservatives felt snubbed at different parts of the process. Earlier this week, McCain delivered an impassioned plea on the Senate floor to return to regular order.

Rounds, the South Dakota Republican, raised serious doubts that regular order could help deliver a solution.

“Well, we’re running out of time now. And that’s the problem—now we have to use regular order. Regular order takes a lot of time, and it’s more challenging. And I’m not sure we’re going to be able to fix this thing,” Rounds told The Daily Beast.