Mr. McCain cautioned his colleagues to ignore “bombastic” pundits. “To hell with them,” he said to applause as he implored his colleagues to work in a bipartisan manner — a provocative message after a hyperpartisan vote. (Fifty Republicans voted to take up the health care debate and two voted no. Forty-six Democrats and two independents voted no.)

On social media, Mr. McCain took a beating in the 24 hours after he said he would make the five-hour flight to Washington to vote for what many viewed as a bill to take away health care from poor people when Mr. McCain was receiving the best treatment available. In 2008, Senator Edward M. Kennedy had the same tumor that has sickened Mr. McCain, and the Massachusetts Democrat made a surprise appearance to help Democrats break a filibuster they said would protect access to doctors by older Americans.

Over the last year, Mr. McCain, 80, has displayed every element of his disputatious, droll, scolding, informed, press-loving, press-hating, senatorial self. He has zipped around the world at a pace that has exhausted colleagues decades younger, trying to assure allies rattled by Mr. Trump’s tweets and remarks.

He has remained watchful and characteristically hawkish on all things Russia-related, even as his fellow Republicans have largely shied from the issue since Mr. Trump entered the White House. He has remained bizarrely captivated by the vexing problem of catfish inspection processes. He has cooperated loyally with the party, except when he hasn’t. He brought down a Republican measure to end emissions curbs on methane because he was mad about the Trump administration’s choice for United States trade representative.

But his Teflon veneer showed cracks this spring when he seemed to be occasionally confused and at times more testy than usual. Last month, Mr. McCain seemed muddled while questioning James B. Comey, the former F.B.I. director, at a hearing. Mr. McCain later said his befuddlement was because of a late night watching an Arizona Diamondbacks game. This month, Mr. McCain learned he had brain cancer.