The sudden failure of Republican efforts to repeal the Affordable Care Act early Friday morning marked a significant defeat in the GOP’s quest to dismantle a signature part of President Barack Obama’s legacy and make health care more difficult to obtain for tens of millions of Americans.

Repealing the law had been a core part of Republican messaging for almost a decade. GOP lawmakers in the House voted more than 50 times to repeal the law, and one effort passed the Senate and reached Obama’s desk in 2016 (he unsurprisingly vetoed it).

But even once they gained control of both houses of Congress and the White House, Republicans were unable to get repeal through. The measure the Senate failed to pass early Friday morning, called the Health Care Freedom Act, would have eliminated the penalty Americans face for not having health insurance, and would have canceled enforcement of a requirement that large companies offer insurance to full-time employees until 2025. Three Republicans, Sens. Lisa Murkowski (Alaska), Susan Collins (Maine) and John McCain (Ariz.), joined with Democrats to kill it.

The vote in the wee hours of Friday morning was the final result of a secretive and chaotic process. Senate Republicans first unveiled their health care plan, largely drafted in private, in June, but were never able to get enough support to advance it. The legislation highlighted major divisions in the Republican caucus. Some conservatives argued it did not go far enough to get rid of Obamacare, while others opposed the plan’s deep cuts to Medicaid and the fact that it would leave insurance out of reach for millions of people.

The nonpartisan Congressional Budget Office estimated that at least one version of a Republican health care plan would result in the number of uninsured Americans rising by 22 million by 2026 ― a projection Republicans disputed.

Senate Majority Leader Mitch McConnell (R-Ky.) eventually cobbled together enough votes to move forward with a motion to proceed to debate health care legislation. But Republicans again were unable to get behind a single measure. In a final move, McConnell tried to push the Health Care Freedom Act, a so-called “skinny” bill targeting key provisions of Obamacare. Republicans thought if they could at least get that through, they could then negotiate with the House over the lower chamber’s health care legislation, which narrowly passed earlier this year.

McCain played a key and dramatic role in the debate over the bill. On Tuesday, days after being diagnosed with brain cancer, he returned from Arizona to a standing ovation in the Senate to cast a vote in favor of the motion to proceed. He then gave a lengthy speech decrying the state of business in the Senate. On Friday, despite personal pleas from President Donald Trump and Vice President Mike Pence, McCain cast the decisive vote against the Health Care Freedom Act, causing audible gasps in the Senate chamber. (Predictably, McCain’s eleventh-hour bucking of his party has received far more media attention ― and praise ― than Murkowski and Collins’ more robust opposition to the repeal efforts.)

Trump, who pressured senators to pass the law, responded to the latest GOP defeat with seeming determination to let the Affordable Care Act fail. He also expressed frustration with the legislative process.

McCain, meanwhile, appears eager to move on and work on a defense spending bill. House Speaker Paul Ryan (R-Wis.) said Republicans shouldn’t give up on Obamacare repeal, but also expressed an eagerness to work on tax reform.

In an interview before Friday’s health care vote, Ryan said Republicans needed to do a better job of uniting the caucus on tax reform legislation than they did on health care.

McConnell, in a floor speech after Friday’s vote, said the result was “clearly a disappointing moment” and that it was “time to move on.”

Republicans could, of course, return to an effort to repeal Obamacare. But without a clear consensus on what a replacement health care system would look like, it’s difficult to imagine such an effort would go very differently from what’s already happened.