In Winterset, Mr. Grassley fanned the flames about so-called death panels, saying, “You have every right to fear.”
“We should not have a government program that determines you’re going to pull the plug on Grandma,” Mr. Grassley said then.
The election of Mr. Trump was supposed to be the unlikely answer to a seven-year question for Republicans: how to make good on their agenda-defining oath to undo President Barack Obama’s signature achievement.
But if the death knell came with Mr. McCain’s downward-turned thumb early Friday morning, the bill’s failure has far deeper roots in this star-crossed era of unified Republican government.
A ruling party that never expected to win. A conservative base long primed to accept nothing less than a full repeal. An overpromising and often disengaged president with no command of the policy itself and little apparent interest in selling its merits to the public.
By the time the end came, Vice President Mike Pence — dispatched to the Senate to cast a tiebreaking vote — instead seemed resigned. Ms. Collins had clustered with the other two “no” Republicans, waiting to cast their votes.
“All of the sudden someone tapped on my back and it was the vice president,” Ms. Collins said. “He obviously had heard that John has decided to vote no. He was well aware of my vote and Lisa’s position and he was there to talk to John.
“He said, ‘Boy, are you tough,’ but he softened it by putting his arm around me as he said it.”
For months before that moment, the distress signals had flared.
Days after Mr. Trump’s inauguration, Republicans gathered in Philadelphia for their annual retreat, exulting in their November victories as liquor flowed and Trump-themed socks were tucked into gift bags for lawmakers.
“Think of everything we can achieve,” Mr. Trump told them, predicting the busiest Congress in recent history and placing repeal-and-replace at the front of the line.
Yet in private sessions that week, Republicans worried about being saddled with a politically toxic “Trumpcare,” with some acknowledging that their dual promises — repealing the law swiftly without pulling the rug out from Americans — could not be reconciled.
“Republicans will own it,” Representative Tom McClintock of California said, according to an audio recording from the gathering. “Lock, stock and barrel.”
The House pressed on, slogging through boiling town halls that called to mind the Democrats’ fate in 2009.
Speaker Paul D. Ryan gamely played the salesman, delivering a slide-show presentation on live television with his sleeves rolled up for a bill that his president would eventually deride as “mean.” After pulling a planned vote in March, the House passed its version in May.
Mr. Trump celebrated the one-chamber triumph with a Rose Garden victory ceremony.
Senators were less convinced. From the start, a fissure emerged between those hoping to repeal the law and sort out a replacement later and those who insisted they must be done in tandem. Republican leaders in Congress planned to take the first approach. But that strategy quickly unraveled, with Mr. Trump demanding a simultaneous repeal and replacement.
In the upper chamber, where Republicans hoped to develop their own bill, the stumbles arrived quickly. Senator Mitch McConnell of Kentucky, the majority leader, assembled a working group of 13 senators to draft the legislation — all of them male — excluding Ms. Murkowski and Ms. Collins.
Concerns came not just from moderates like Ms. Collins but from reliable Republicans in some unlikely places: Senator John Hoeven of North Dakota, Senator Jerry Moran of Kansas, Senator Ron Johnson of Wisconsin, who told any reporter within earshot that he did not have enough information to even form a firm opinion.
At the same time, Russia-tinged scandal shadowed Mr. Trump with increasing urgency, delivering a deluge of distractions.
In mid-May, Mr. McCain, who was at the time not considered a potential swing vote on health care legislation, was asked if Republicans might be more willing to buck Mr. Trump on policy issues given the circumstances.
“Are you kidding me?” the senator shot back. “Do you think that I am not known — you think my reputation is that I go along?”
Even on matters specific to health care, Mr. Trump was not helping. At a lunch with Republican senators at the White House in June, he savaged the House measure and called for a more “generous” bill in the Senate, injecting himself into the chamber’s delicate negotiations.
Ms. Murkowski was seated directly to Mr. Trump’s right. As he ticked off soaring premiums in different states, the president leaned over to her. “I hate to say this to you, Lisa, but in Alaska, they’ve gone up 207 percent on Obamacare,” he said.
Weeks later, at another White House lunch, another fence-sitting Republican, Senator Dean Heller of Nevada, was seated in the same position. “Look, he wants to remain a senator, doesn’t he?” Mr. Trump said.
The recruitment efforts grew more ham-fisted with time. After a vote on Tuesday to proceed to a debate on health care repeal, which only Ms. Murkowski and Ms. Collins opposed among Republicans, Ms. Murkowski received a phone call: Mr. Trump had directed his interior secretary, Ryan Zinke, to remind the senator of issues affecting her state that are controlled by the Interior Department, according to people familiar with the call.
And Mr. McCain’s startling diagnosis of brain cancer had an impact — and not just on him.
“That was the low point,” Ms. Collins said, recalling a phone call with Mr. McCain after the diagnosis. “It made me realize that even though I was under a lot of pressure, it didn’t compare to what he was going through. It reminded me of how very personal and important health care is.”
On that initial vote, Mr. McCain had been a qualified yes, returning from treatment to deliver a short-term balm to Mr. Trump and his fellow Republicans.
But his final decision awaited. He joked, on his return, that he would soon give his peers cause to regret all the nice things they had said about him.
Mr. McCain had come back to the Capitol with a plea for his colleagues, delivered on Tuesday in a soaring address from the floor: “Let’s trust each other,” he said, lamenting the state of the institution. “Let’s return to regular order.”
All week after that, Democrats approached him, praising the speech, with a request of their own: Help the Senate get there.
“I know,” Mr. McCain told them repeatedly. “I know.”
As Thursday night slid toward Friday morning, a group of Republicans, including Mr. McCain, demanded assurances from Mr. Ryan that the House would not simply pass the slapdash legislation that many viewed as a placeholder.
The White House thought it had persuaded Mr. McCain by assuaging him on two fronts: Administration officials had been in touch with Gov. Doug Ducey of Arizona, whom Mr. McCain had looked to for guidance, and nudged the governor to make clear to Mr. McCain that he was in favor of keeping the process going. And Trump aides made certain that Mr. Ryan assured Mr. McCain in a phone call that the so-called “skinny” repeal bill at hand would not become law. Mr. McConnell appeared confident as well, for a time.
But Mr. McCain’s decision was so shrouded in mystery that his closest friend in the Senate, Lindsey Graham, and longtime aide and muse, Mark Salter, were not quite sure early Thursday evening how he would vote.
“Wait for the show,” Mr. McCain told reporters asking for a preview.
When Mr. McCain reached the floor in the wee hours of Friday morning, Mr. Pence was eager to speak to him. The vice president made clear that he, too, thought little of the bill at hand but that it was more important to go to a bicameral conference committee where a new measure could be hashed out, Mr. Graham said.
Before long, Mr. McCain left to take a call in the cloakroom. It was Mr. Trump, echoing Mr. Pence’s argument.
Democrats stirred. “Not sure how vote will turn out,” Senator Claire McCaskill, Democrat of Missouri, said on Twitter, “but we have a shot.”
Mr. Trump has spoken often of leverage in negotiations. On Friday, he had none. It is difficult, in the best of circumstances, to strong-arm an octogenarian war hero battling brain cancer.
And two years ago this month — in Iowa, inevitably — Mr. Trump had disparaged him for being captured in combat.
“The three who voted against it have a very negative relationship with the president,” said Senator Bill Cassidy, Republican of Louisiana. For Mr. McCain in particular, he said, “He’s not one where you’d expect a phone call to make the difference.”
Shuffling across the chamber, Mr. McCain convened with Democrats, informing them of his choice. “They can read my lips,” he said to laughs, fearing his hand would be tipped ahead of time from inside the gallery.
At one point, the senator joined Ms. Collins and Ms. Murkowski, telling them they had done the right thing.
“We talked about how if anyone knew about doing the right thing it was John McCain,” Ms. Collins recalled. “It was very moving.”
By 1:30 a.m., Mr. McCain returned to the middle of the floor, a few feet from where he had spoken of bipartisanship and comity on Tuesday. Mr. McConnell stared straight ahead, motionless, as the Republican promise fell away.
Mr. McCain held out his arm, waiting to be recognized once more, and dropped his thumb.