(Jon Elswick/AP President Trump’s president’s own health care agenda would be undercut by the loss of the law that empowers the administration to pilot new ideas.)

A Texas judge’s decision to declare the Affordable Care Act unconstitutional has spooked Republicans who are unsure whether they have realized the long-sought victory celebrated by President Trump or stumbled into a nightmare that will haunt them through the next election cycle.

They had already killed or softened its most loathed sections: The reviled penalty for not having health insurance was zeroed out as part of last year’s tax overhaul. The Trump administration had expanded access to far less robust — and much cheaper — insurance than the law mandated. It even allowed states to impose work rules on those eligible for expanded Medicaid benefits.

However, scrapping the law altogether puts them back in the hot seat: If the ruling is upheld on appeal, it will leave Republicans in Congress scrambling — again — to preserve the health-care benefits Americans demand, from protections for those with preexisting conditions, to free preventive care and allowing parents to keep their children on their policies until they turn 26.

It also undermines the president’s own health-care agenda, particularly his vows to rein in prescription drug prices and ramp up the response to the opioid crisis, both of which crucially depend on the law’s provisions.

“This lawsuit became a rallying cry for the conservative base. But now, with the breadth of the judge’s decision, it might be as much of headache as a rallying cry,” said Larry Levitt, senior vice president for health reform at the Kaiser Family Foundation, a nonpartisan health policy group. “If this decision is upheld, then we’re right back into a massive national debate on the future of the ACA, and that would hijack anything else the Trump administration wanted to do on health care — or anything the Trump administration wanted to do, for that matter.”

Nothing changes immediately. The signature health-care law of former president Barack Obama will remain in place as an appeal winds its way through the courts — something the Trump administration strained to make clear, even as the president celebrated the court ruling on Twitter as “great news for America!”

Political and legal analysts consider it probable that the case will end up before the Supreme Court in the run-up to the 2020 election, turning health care into the dominant issue of another election cycle.

“Republicans have chipped away at the core of the ACA very significantly, and one of the things I think they have struggled with is the ability to message that this is achieving their ends,” said Rodney L. Whitlock, vice president of ML Strategies and a Republican Hill staffer when the law was written. “I don’t think that nearly the majority of Republicans favor repeal of all the provisions. There’s no victory in root-and-branch repeal.”

That’s partly because congressional Republicans failed several times to come up with a plan to replace the ACA that would preserve its popular benefits. If the law is tossed, Congress would be forced to reckon with how the ACA has fundamentally reshaped Americans’ expectations of the health-care system.

“Trump did make a statement about how this court decision was good, because now there would be a real health plan, but he never said what that would be,” said Joseph Antos, resident scholar at the conservative-leaning American Enterprise Institute, who characterized the GOP plan to fix the market for people without work coverage as “an empty bag of ideas.”

“I think Republicans have been pretty quiet about it, because they beat each other up in 2017 and accomplished nothing,” he added.

More immediately, President Trump’s health-care agenda would be undercut by the loss of the law, which empowers the administration to pilot new ideas.

“It totally hinges on the ACA — I mean totally,” said Joshua Sharfstein, a health policy expert at the Johns Hopkins Bloomberg School of Public Health who served as principal deputy commissioner at the Food and Drug Administration under President Obama.

Trump has championed a plan to cut spending on some of the most expensive prescription drugs in Medicare, but that depends on authority granted by the ACA to allow the government to experiment with new ways to pay for health care without going through Congress. Health and Human Services Secretary Alex Azar has taken advantage of that to transition how Medicare pays for health care, one of his top priorities.

The law also created a pathway for cheaper, copycat versions of some of the most expensive drugs on the market. And Medicaid expansion has helped cover people fighting opioid addiction, credited as a key tool by Ohio Gov. John Kasich, a Republican, whose state is one of the hardest hit by the crisis.

In a statement, the Department of Health and Human Services said nothing was changing for the moment and noted the decision was not a final judgment and did not halt enforcement of the law.

“Therefore, HHS will continue administering and enforcing all aspects of the ACA as it had before the court issued its decision,” spokeswoman Caitlin Oakley said. She did not respond to questions about whether the decision undermined the Trump administration’s health-care priorities.

Health policy experts said the biggest impact of the judge’s decision — because it is unlikely to have any tangible impact for months or years — is its effect on public and private uncertainty and planning by various parts of the health-care system. Health-care industry groups, including health insurers, hospitals, physicians and patient groups quickly criticized the decision.

“I think the short-term effect is not in terms of the law, but in terms of the public psychology, which is: This isn’t safe. This isn’t secure. This is constantly under attack,” said Ezekiel Emanuel, a health policy expert at the University of Pennsylvania and one of the architects of the Affordable Care Act. “Let’s say you get an appeals court decision a year from now that upholds this decision, and they say the whole ACA is unconstitutional. What is 2020 going to be all about? It’s going to be about health care.”