WASHINGTON — The Senate narrowly defeated a bill early Friday that would have repealed limited portions of Obamacare as Republican Sen. John McCain cast the deciding vote against the plan.

Senators voted 49-51 for the bill, falling two votes short of the 51 votes needed to pass the legislation. In addition to McCain, the Republicans who voted against the bill were Sens. Susan Collins of Maine and Lisa Murkowski of Alaska.

The vote was a major blow to GOP Senate leaders. House and Senate Republicans campaigned on a promise to repeal and replace the Affordable Care Act, but they have struggled to reach consensus on how to do that.

Senate Majority Leader Mitch McConnell, R-Ky., Vice President Pence and other GOP leaders could be seen lobbying McCain and Murkowski on the Senate floor before the vote. But it was clear when Democrats hugged McCain that the bill would fail.

McConnell said at about 2 a.m. that it was "time to move on" rather than trying again to pass a GOP bill. He said he wants to hear ideas from Democrats about what to do next on health care.

"What we tried to accomplish for the American people was the right thing for the country," McConnell, who was clearly shaken, said after the vote. "And our only regret is that we didn't achieve what we had hoped to accomplish. I think the American people are going to regret that we couldn't find a better way forward."

Senate Minority Leader Chuck Schumer, D-N.Y., said Democrats are eager to work with Republicans to improve Obamacare.

"We are not celebrating," Schumer said. "We are relieved ... not for ourselves, but for the American people."

Schumer's voice broke as he praised McCain for his courage in casting the deciding vote. The Arizona senator learned last week that he has a brain tumor but returned to Capitol Hill this week so he could vote on health care. He voted Tuesday to allow the Senate to debate the GOP bills, but he made no promises to support them.

“From the beginning, I have believed that Obamacare should be repealed and replaced with a solution that increases competition, lowers costs, and improves care for the American people. The so-called ‘skinny repeal’ amendment the Senate voted on today would not accomplish those goals," McCain said in a statement after the vote.

President Trump tweeted that the three Republicans and 48 Democrats "let the American people down."

"As I said from the beginning, watch ObamaCare implode, then deal. Watch!" Trump tweeted.

The non-partisan Congressional Budget Office said the defeated bill, dubbed the Health Care Freedom Act, would have resulted in 16 million fewer Americans with medical coverage by 2026. It also would have increased premiums by about 20% for people buying their insurance in the individual marketplace every year between 2018 and 2026.

McConnell said the bill would have ended the mandates that individuals buy health insurance and that larger employers offer affordable coverage to their workers. He said it also would have provided more flexibility to states in providing medical care to low-income Americans and repealed the medical device tax for three years while increasing the amount of money that people could contribute to Health Savings Accounts.

The provision to defund Planned Parenthood drew opposition from Collins and Murkowski.

"The American people have suffered under Obamacare for too long," McConnell said in a speech on the Senate floor Thursday night. "It’s time to end the failed status quo. It’s time to send legislation to the president that will finally move our country beyond the failures of Obamacare. Passing this legislation will allow us to work with our colleagues in the House toward a final bill that can go to the president, repeal Obamacare, and undo its damage."

The American Medical Association immediately denounced the bill.

"The so-called 'skinny' bill is a toxic prescription that would make matters worse," said AMA President David Barbe. "Eliminating the individual mandate will lead to adverse selection, triggering higher premiums and further destabilizing the individual market. The stated goal was to advance policies to lower premiums, but the 'skinny' bill would do the exact opposite, harming patients across the country."

McCain and Sens. Lindsey Graham, R-S.C. and Ron Johnson, R-Wis., announced earlier in the evening that they would not support a "skinny repeal" bill unless they had a guarantee the House would actually start negotiations and not simply pass the Senate bill and send it to President Trump.

House Speaker Paul Ryan, R-Wis., tried to provide that assurance by saying the House would be "willing" to go to conference if that was what was required to move a bill forward. That won over Graham and Johnson, but McCain said it didn't go far enough in assuring him that the House wouldn't vote on the skinny repeal at some point.

"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.

Friday's vote was the third — and most devastating — defeat this week for Republican leaders. The Senate rejected a leadership plan to replace Obamacare on Tuesday night 43-57, with nine Republicans voting against it. And on Wednesday, a clean repeal of the health care law — with a two-year delay to come up with a replacement — failed 45-55.

Contributing: Nicole Gaudiano

Read more:

McCain, battling cancer, returns to Senate and casts critical health care vote

Democrats seize on John McCain’s message in health care fight