WASHINGTON — A federal judge in Texas struck down Friday the entire Affordable Care Act on the grounds that its mandate requiring people to buy health insurance is unconstitutional and the rest of the law cannot stand without it.

The ruling was on a lawsuit filed this year by a group of Republican governors and state attorneys general. A group of intervening states led by Democrats promised to appeal the decision, which will most likely not have any immediate effect. But it will almost certainly make its way to the Supreme Court, threatening the survival of the landmark health law and, with it, health coverage for millions of Americans, protections for people with pre-existing conditions and much more.

In his ruling Friday, Judge Reed O’Connor of U.S. District Court in Fort Worth said that the individual mandate requiring people to have health insurance “can no longer be sustained as an exercise of Congress’ tax power.”

Accordingly, O’Connor, a George W. Bush appointee, said that “the individual mandate is unconstitutional” and the remaining provisions of the Affordable Care Act are invalid.

At issue was whether the health law’s insurance mandate still compelled people to buy coverage after Congress reduced the penalty to zero dollars as part of the tax overhaul that President Donald Trump signed last December. When the Supreme Court upheld the mandate as constitutional in 2012, it was based on Congress’ taxing power. Congress, the court said, could legally impose a tax penalty on people who do not have health insurance.

But in the new case, the plaintiffs, led by Texas, argued that with the penalty zeroed out, the individual mandate had become unconstitutional — and that the rest of the law could not be severed from it.

The Justice Department’s response to the case was highly unusual: though it disagreed with the plaintiffs that the entire law should be struck down, it declined this year to defend not just the individual mandate, but the law’s provisions that protect people with pre-existing conditions. That prompted a coalition of 16 states and the District of Columbia, led by California, to intervene and defend the law.

On Friday night, a spokeswoman for Xavier Becerra, the California attorney general, said California and the other defendant states would challenge the ruling with an appeal in the 5th U.S. Circuit Court of Appeals.

“Today’s ruling is an assault on 133 million Americans with pre-existing conditions, on the 20 million Americans who rely on the ACA’s consumer protections for health care, on America’s faithful progress toward affordable health care for all Americans,” Becerra said in a statement. “The ACA has already survived more than 70 unsuccessful repeal attempts and withstood scrutiny in the Supreme Court.”

Trump, who has consistently sought the law’s repeal and has weakened it through regulatory changes, posted a response to the ruling on Twitter late Friday: “As I predicted all along, Obamacare has been struck down as an UNCONSTITUTIONAL disaster! Now Congress must pass a STRONG law that provides GREAT healthcare and protects pre-existing conditions.”