DOYLESTOWN, Pa. — Five years ago, the Affordable Care Act had yet to begin its expansion of health insurance to millions of Americans, but Jeff Brahin was already stewing about it.

“It’s going to cost a fortune,” he said in an interview at the time.

This week, as Republican efforts to repeal the law known as Obamacare appeared all but dead, Mr. Brahin, a 58-year-old lawyer and self-described fiscal hawk, said his feelings had evolved.

“As much as I was against it,” he said, “at this point I’m against the repeal.”

“Now that you’ve insured an additional 20 million people, you can’t just take the insurance away from these people,” he added. “It’s just not the right thing to do.”

As Mr. Brahin goes, so goes the nation.

When President Trump was elected, his party’s long-cherished goal of dismantling the Affordable Care Act seemed all but assured. But eight months later, Republicans seem to have done what the Democrats who passed the law never could: make it popular among a majority of Americans.

Support for the Affordable Care Act has risen since the election — in some polls, sharply — with more people now viewing the law favorably than unfavorably. Voters have besieged their representatives with emotional telephone calls and rallies, urging them not to repeal, one big reason Republicans have had surprising trouble in fulfilling their promise despite controlling both Congress and the White House.

The change in public opinion may not denote newfound love of the Affordable Care Act so much as dread of what might replace it. The nonpartisan Congressional Budget Office estimates that both the House and Senate proposals to replace the law would result in over 20 million more uninsured Americans. The shift in mood also reflects a strong increase in support for Medicaid, the health insurance program for the poor that the law expanded to cover far more people, and which faces the deepest cuts in its 52-year history under the Republican plans.

Most profound, though, is this: After years of Tea Party demands for smaller government, Republicans are now pushing up against a growing consensus that the government should guarantee health insurance. A Pew survey in January found that 60 percent of Americans believe the federal government should be responsible for ensuring that all Americans have health coverage. That was up from 51 percent last year, and the highest in nearly a decade.

The belief held even among many Republicans: 52 percent of those making below $30,000 a year said the federal government has a responsibility to ensure health coverage, a huge jump from 31 percent last year. And 34 percent of Republicans who make between $30,000 and about $75,000 endorsed that view, up from 14 percent last year.

“The idea that you shouldn’t take coverage away really captured a large share of people who weren’t even helped by this bill,” said Robert Blendon, a health policy expert at Harvard who has closely followed public opinion of the Affordable Care Act.

In 2012, when The New York Times talked to Mr. Brahin and others here in Bucks County, Pa., a perennial swing district outside Philadelphia, their attitudes on the law tracked with national polls that showed most Americans viewed it unfavorably.

But now, too, sentiment here reflects the polls — and how they have shifted. Many people still have little understanding of how the law works. But Democrats and independents have rallied around it, and many of those who opposed it now accept the law, unwilling to see millions of Americans stripped of the coverage that it extended to them.

“I can’t even remember why I opposed it,” said Patrick Murphy, who owns Bagel Barrel, on a quaint and bustling street near Mr. Brahin’s law office here in Doylestown.

He thought Democrats “jammed it down our throats,” and like Mr. Brahin, he worried about the growing deficit. But, he said, he has provided insurance for his own dozen or so employees since 1993.

“Everybody needs some sort of health insurance,” Mr. Murphy said. “They’re trying to repeal Obamacare but they don’t have anything in place.”

Five years ago, people here could barely turn on their televisions without seeing negative ads warning that the Affordable Care Act would lead to rationed care and bloated bureaucracy. The law’s supporters, meanwhile, including the president whose name is attached to it, were not making much of a case.

To win support, Democrats were emphasizing that little would change for people who already had coverage; President Barack Obama famously promised that you could keep your plan and your doctor, even as a few million people’s noncompliant plans that did not offer all the law’s required benefits were canceled as the law was rolled out.

“The best way to get something passed was to argue it was small change,” said Stanley Greenberg, a veteran Democratic pollster. “It was only when Republicans got control that people then on their own discovered that this is what the benefits are.”

Jennifer Bell, sitting outside Mr. Murphy’s bagel shop with a friend, was raised a Democrat and always supported the health care law. But it was only after she was injured in a serious car accident in 2013 that she thought to advocate for it. She used to get health insurance through her job as a teacher. Now disabled with extensive neurological damage, and working part-time in a record store, she qualifies for Medicaid, and without it, she said, could not afford her ongoing treatment.

“It’s very, very scary to think about not having health insurance,” she said.

“If the condition doesn’t kill you, the stress of having it does, in this country,” she added. “The fact that people do without health insurance is a sin, in my opinion.”

Ms. Bell, 35, joined about 2,000 others for a women’s march in Doylestown after the inauguration, and now makes calls to Representative Brian Fitzpatrick and Senator Patrick J. Toomey, both Republicans, urging them to protect the Affordable Care Act. She is working to elect a Democrat challenging Mr. Fitzpatrick, who voted against the House bill to replace the law, saying he worried about people losing coverage.

More vigorous support among the law’s natural constituents since Mr. Trump’s election has helped lift public opinion. The Kaiser Family Foundation polls tracking monthly support for the law have shown the greatest gains among Democrats and independents, with an increase of 10 to 12 points among each group over the last year, while Republicans’ opinion has remained as unfavorable as ever.

“When something is threatened to be taken away, people start to rally around it,” said Liz Hamel, the director of public opinion and survey research for Kaiser, a nonpartisan group.

There has been an increase in the percentage of Republicans and Democrats saying that Medicaid is important for them and their families; between February and July the percentage of Republicans saying so had increased 10 points, to 53 percent.

The law still faces hurdles even beyond the debate in Congress. Five years ago, Cindy McMahon, who works at the store on the vegetable farm her family has owned for nearly a century, was not intending to buy health insurance, despite the law’s requirement that people have it or pay a tax penalty. She remains uninsured (and the Trump administration has suggested it may not enforce the penalty).

“If I had to pay a penalty, it’s still less than I have to pay for having health care all year,” Ms. McMahon said. At 52, she has diabetes and says the strips to test her blood sugar are so expensive that sometimes she tests once a month rather than daily. She has not looked into whether she might qualify for the Medicaid expansion; she was not aware Pennsylvania had expanded the program.

Frank Newport, the editor in chief of Gallup, said that the area of biggest agreement in polls is that Americans want the law changed. In the most recent poll, 44 percent of Americans said Congress should keep the law but make “significant changes.” That compares with 23 percent who want to keep it as it is, and 30 percent who support the Republicans’ plan to repeal and replace it.

Mr. Greenberg said the growing belief that the government should make sure people have health coverage was less an outbreak of compassion than a matter of affordability. In focus groups he conducted, Trump voters said they wanted the president and Congress to lower their health insurance premiums; they did not want to lose the Affordable Care Act’s protections against insurers charging more to people with pre-existing conditions, or denying coverage of basic health benefits.

Mark Goracy, an insurance consultant in Langhorne, near Doylestown, calls the coverage he and his wife get through the individual market “a joke.” Their premium is $1,415 a month, with combined deductibles of more than $12,000.

Still, Mr. Goracy, 62, said he nonetheless wants the law’s mandate blocking insurers from charging people more because of pre-existing conditions to survive.

While he once wished for “root-and-branch” repeal of the Affordable Care Act, he is not disappointed about the Republican failure to repeal it.

“Unlike when Democrats passed A.C.A. with not one Republican vote, what the Republicans need to do is get together with 20 or 25 Democrats and pass some kind of reform,” he said. “That, to me, is how legislation is supposed to proceed.”