WASHINGTON (AP) — The Supreme Court dismissed a major challenge to the Obama era health care law on Thursday, turning aside an effort by Republican-led states to throw out the law that provides insurance coverage for millions of Americans.

The justices, by a 7-2 vote, left the entire law intact in ruling that Texas, other GOP-led states and two individuals had no right to bring their lawsuit in federal court. The Biden administration says 31 million people have health insurance because of the law popularly known as “Obamacare.”

The law’s major provisions include protections for people with pre-existing health conditions, a range of no-cost preventive services and the expansion of the Medicaid program that insures lower-income people, including those who work in jobs that don’t pay much or provide health insurance.

Also left in place is the law’s now-toothless requirement that people have health insurance or pay a penalty. Congress rendered that provision irrelevant in 2017 when it reduced the penalty to zero.

The elimination of the penalty had become the hook that Texas and other Republican-led states, as well as the Trump administration, used to attack the entire law. They argued that without the mandate, a pillar of the law when it was passed in 2010, the rest of the law should fall, too.

And with a more conservative Supreme Court that includes three Trump appointees, opponents of Obamacare hoped a majority of the justices would finally kill off the law they have been fighting against for more than a decade.

But the third major attack on the law at the Supreme Court ended the way the first two did, with a majority of the court rebuffing efforts to gut the law or get rid of it altogether.

Trump’s three appointees to the Supreme Court — Justices Amy Coney Barrett, Neil Gorsuch and Brett Kavanaugh — split their votes. Kavanaugh and Barrett joined the majority. Gorsuch was in dissent, signing on to an opinion from Justice Samuel Alito.

Justice Stephen Breyer wrote for the court that the states and people who filed a federal lawsuit “have failed to show that they have standing to attack as unconstitutional the Act’s minimum essential coverage provision.”

In dissent, Alito wrote, “Today’s decision is the third installment in our epic Affordable Care Act trilogy, and it follows the same pattern as installments one and two. In all three episodes, with the Affordable Care Act facing a serious threat, the Court has pulled off an improbable rescue.” Alito was a dissenter in the two earlier cases, as well.

Like Alito, Justice Clarence Thomas was in dissent in the two earlier cases, but he joined Thursday’s majority, writing, “Although this Court has erred twice before in cases involving the Affordable Care Act, it does not err today.”

Because it dismissed the case for the plaintiff’s lack of legal standing — the ability to sue — the court didn’t actually rule on whether the individual mandate is unconstitutional now that there is no penalty for forgoing insurance. Lower courts had struck down the mandate, in rulings that were wiped away by the Supreme Court decision.

With the latest ruling, the ACA is “here to stay for the foreseeable future,” said Larry Levitt, an executive vice president for the non-profit Kaiser Family Foundation, which studies health care.

“Democrats are in charge and they have made reinvigorating and building on the ACA a key priority,” Levitt said. “Republicans don’t seem to have much enthusiasm for continuing to try to overturn the law.”

Republicans pressed their argument to invalidate the whole law even though congressional efforts to rip out the entire law “root and branch,” in Senate GOP Leader Mitch McConnell’s words, have failed. The closest they came was in July 2017 when Arizona Sen. John McCain, who died the following year, delivered a dramatic thumbs-down vote to a repeal effort by fellow Republicans.

Chief Justice John Roberts said during arguments in November that it seemed the law’s foes were asking the court to do work best left to the political branches of government.

The court’s decision preserves benefits that became part of the fabric of the nation’s health care system.

Polls show that the 2010 health care law grew in popularity as it endured the heaviest assault. In December 2016, just before Obama left office and Trump swept in calling the ACA a “disaster,” 46% of Americans had an unfavorable view of the law, while 43% approved, according to the Kaiser Family Foundation tracking poll. Those ratings flipped and by February of this year 54% had a favorable view, while disapproval had fallen to 39% in the same ongoing poll.

The health law is now undergoing an expansion under President Joe Biden, who sees it as the foundation for moving the U.S. to coverage for all. His giant COVID-19 relief bill significantly increased subsidies for private health plans offered through the ACA’s insurance markets, while also dangling higher federal payments before the dozen states that have declined the law’s Medicaid expansion. About 1 million people have signed up with HealthCare.gov since Biden reopened enrollment amid high levels of COVID cases earlier this year.

Most of the people with insurance because of the law have it through Medicaid expansion or the health insurance markets that offer subsidized private plans. But its most popular benefit is protection for people with pre-existing medical conditions. They cannot be turned down for coverage on account of health problems, or charged a higher premium. While those covered under employer plans already had such protections, “Obamacare” guaranteed them for people buying individual policies.

Another hugely popular benefit allowed young adults to remain on their parents’ health insurance until they turn 26. Before the law, going without medical coverage was akin to a rite of passage for people in their 20s getting a start in the world.

Because of the ACA, most privately insured women receive birth control free of charge. It’s considered a preventive benefit covered at no additional cost to the patient. So are routine screenings for cancer and other conditions.

For Medicare recipients, “Obamacare” also improved preventive care, and more importantly, closed a prescription drug coverage gap of several thousand dollars that was known as the “doughnut hole.”

___