WASHINGTON — Sen. John McCain returned to the U.S. Capitol on Tuesday afternoon to cast a critical vote in favor of health care legislation less than a week after undergoing surgery and revealing he has brain cancer.

And then, in typical McCain fashion, he took to the floor and blasted both the Senate's draft health care bill and the process that produced it.

"All we’ve managed to do is make more popular a policy that wasn’t very popular when we started trying to get rid of it," he said of Obamacare.

McCain’s vote was pivotal as Republicans, who hold a 52-seat majority, scrambled to round up 50 votes on a motion to advance legislation to repeal Obamacare.

McCain did not announce in advance whether he would support Tuesday’s “motion to proceed,” but he marched onto the floor to a standing ovation from his colleagues and voted "aye." Republican Sens. Susan Collins of Maine and Lisa Murkowski of Alaska voted no, requiring Vice President Pence to cast the tie-breaking vote in favor.

But that was only a vote to begin debate. "I will not vote for this bill as it is today," McCain said, and if it fails, "which seems likely," the Senate should go back to the drawing board, with hearings, markups and consultation with Democrats — all things that have thus far been lacking.

Standing in the well of the Senate with the surgical scar over his left eyebrow clearly visible, McCain urged his colleagues to "stop listening to the bombastic loudmouths" on radio, television and the Internet who rail against compromise. "To hell with them!" McCain said.

Democrats, including Senate Minority Leader Chuck Schumer of New York, were seen smiling during McCain's speech as he railed against Republicans crafting legislation behind closed doors and trying to convince skeptical members that it's better than nothing.

“Let’s trust each other," McCain said. "We’ve been spinning our wheels on too many important issues because we keep trying to find a way to win without help from across the aisle."

McCain left the Capitol with his wife, Cindy, after his speech, canceling a scheduled news conference.

His announcement Monday that he would return for the vote added momentum to Republican efforts in the Senate following House Republicans’ passage of their bill in May.

“We all know Sen. McCain is a fighter,” said Majority Leader Mitch McConnell of Kentucky during a Senate floor speech Tuesday. “That’s evidenced by his remarkable life of public service, just as it’s again evidenced by his quick return to the Senate this afternoon.”

Read more:

Senate Republicans clear key hurdle on Obamacare repeal, but the hard part is still ahead

Full text of John McCain's Senate floor speech: 'Let’s return to regular order'

Internet reacts to Sen. John McCain's speech after procedural vote

McCain, 80, a decorated Vietnam War veteran and six-term senator, is battling glioblastoma, an aggressive type of brain cancer that is difficult to treat. The cancer was discovered during surgery to treat a blood clot above his eye. He is reviewing treatment options, which may include chemotherapy and radiation, with his care team at the Mayo Clinic.

On the Senate floor, he hugged his colleagues and joked about his well-wishers.

"I’ve had so many people say such nice things about me recently that I think some of you must have me confused with someone else," he said.

President Trump, who has criticized McCain in the past, tweeted his thanks early Tuesday morning and then again after the vote.

".@SenJohnMcCain-Thank you for coming to D.C. for such a vital vote. Congrats to all Rep. We can now deliver grt healthcare to all Americans!" he wrote.

Others blasted McCain on Twitter for leaving taxpayer-supported treatment to help pass legislation that —according to a Congressional Budget Office analysis — would lead to more than 20 million fewer people having insurance by 2026.

“After brain surgery paid for by taxpayers,@SenJohnMcCain will vote to take away healthcare from 22 million Americans,” tweeted Jon Cooper, chairman of the Democratic Coalition, which describes itself as an anti-Trump organization.

McCain, who chairs the Senate Armed Services Committee, said he will stay in D.C. "for a few days" and plans to return to work on the National Defense Authorization Act, among other issues.

“After that, I’m going home for a while to treat my illness," he said. "I have every intention of returning here and giving many of you cause to regret all the nice things you said about me."

Contributing: Ronald J. Hansen, The Arizona Republic, and Eliza Collins, USA TODAY.