Sen. John McCain returned to the U.S. Senate after being diagnosed with brain cancer on Tuesday, July 25, 2017.

WASHINGTON (AP) — Prodded by President Donald Trump, a bitterly divided Senate voted, at last, Tuesday to move forward with the Republicans' long-promised legislation to repeal and replace "Obamacare." There was high drama as Sen. John McCain returned to the Capitol for the first time after being diagnosed with brain cancer to cast a decisive "yes" vote.

The final tally was 51-50, with Vice President Mike Pence breaking the tie after two Republicans joined all 48 Democrats in voting "no."

With all senators in their seats and protesters agitating outside and briefly inside the chamber, the vote was held open at length before McCain, 80, entered the chamber. Greeted by cheers, he smiled and dispensed hugs — but with the scars from recent surgery starkly visible on the left side of his face.

Despite voting "yes," he took a lecturing tone afterward and hardly saw success assured for the legislation after weeks of misfires, even after Tuesday's victory for Trump and Republican leader Mitch McConnell.

"If this process ends in failure, which seems likely, then let's return to regular order," McCain said as he chided Republican leaders for devising the legislation in secret along with the administration and "springing it on skeptical members."

"Stop listening to the bombastic loudmouths on the radio, TV and internet. To hell with them!" McCain said, raising his voice as he urged senators to reach for the comity of earlier times.

When the Senate voted Tuesday evening on the bill's initial amendment, it underscored how hard it will be for the chamber's divided Republicans to pass a sweeping replacement of Obama's law.

By 57-43 — including nine GOP defectors — it blocked a wide-ranging proposal by McConnell to erase and replace much of the statute. It included language by Sen. Ted Cruz, R-Texas, letting insurers sell cut-rate policies with skimpy coverage, plus an additional $100 billion to help states ease out-of-pocket costs for people losing Medicaid sought by Midwestern moderates including Rob Portman, R-Ohio.

But at the White House earlier after senators voted to consider the bill, Trump wasted no time in declaring a win and slamming the Democrats anew.

"I'm very happy to announce that, with zero of the Democrats' votes, the motion to proceed on health care has just passed. And now we move forward toward truly great health care for the American people," Trump said. "This was a big step. I want to thank Senator John McCain — very brave man."

Trump continued to celebrate the vote at a rally in Youngstown, Ohio that doubled as a victory lap.

"We're now one step closer to liberating our citizens from this Obamacare nightmare and delivering great health care for the American people" he said.

At its most basic, the Republican legislation is aimed at undoing Obamacare's unpopular mandates for most people to carry insurance and businesses to offer it. The GOP would repeal Obamacare taxes and unwind an expansion of the Medicaid program for the poor, the disabled and nursing home residents The result would be 20 million to 30 million people losing insurance over a decade, depending on the version of the bill.

The GOP legislation has polled abysmally, while Obamacare itself has grown steadily more popular. Yet most Republicans argue that failing to deliver on their promises to pass repeal-and-replace legislation would be worse than passing an unpopular bill, because it would expose the GOP as unable to govern despite controlling majorities in the House, Senate and White House.

Tuesday's vote amounted to a procedural hurdle for legislation whose final form is impossible to predict under the Senate's byzantine amendment process, which will unfold over the next several days.

Indeed senators had no clear idea of what they would ultimately be voting on, and in an indication of the uncertainty ahead, McConnell said the Senate will "let the voting take us where it will." The expectation is that he will bring up a series of amendments, including a straight-up repeal and fuller replacement legislation, to see where consensus may lie.

Yet after seven years of empty promises, and weeks of hand-wringing and false starts on Capitol Hill, it was the Senate's first concrete step toward delivering on innumerable pledges to undo former President Barack Obama's law. It came after several near-death experiences for earlier versions of the legislation, and only after Trump summoned senators to the White House last week to order them to try again after McConnell had essentially conceded defeat.

"The people who sent us here expect us to begin this debate, to have the courage to tackle the tough issues," McConnell said ahead of the vote.

Democrats stood implacably opposed, and in an unusual maneuver they sat in their seats refusing to vote until it was clear Republicans would be able to reach the 50-vote margin needed to get them over the top with Pence's help.

"Turn back," Minority Leader Chuck Schumer of New York implored his GOP colleagues before the vote. "Turn back now, before it's too late and millions and millions and millions of Americans are hurt so badly."

Schumer's pleas fell on deaf ears, as several GOP senators who'd announced they would oppose moving forward with the legislation reversed themselves to vote "yes." Among them were Dean Heller of Nevada, the most vulnerable Republican senator in next year's midterm elections, Shelley Moore Capito of West Virginia and Ron Johnson of Wisconsin.

Johnson has recently accused McConnell of operating in bad faith on the bill, and stood in intense conversation with him on the Senate floor before finally becoming the 50th Republican senator to vote "yes," immediately following McCain.

Democratic campaign groups immediately announced they would be targeting Heller and others with ads. The two Republicans voting "no" were Susan Collins of Maine and Lisa Murkowski of Alaska.