WASHINGTON—The Supreme Court rejected a challenge to the Affordable Care Act from Republican-led states in a 7-2 decision, ruling that they lacked standing to bring the case.

Texas and other Republican-leaning states, backed by the Trump administration, had sought to strike down the law on technical arguments after Congress reduced to zero the tax penalty for failing to carry health insurance. Thursday’s decision, written by Justice Stephen Breyer, concluded that none of the plaintiffs suffered any injury from zeroing out the penalty and thus lacked legal standing to bring the lawsuit at all. It was the third time the court has preserved the 2010 healthcare law.

“We do not reach these questions of the Act’s validity,” Justice Breyer wrote. “Texas and the other plaintiffs in this suit lack the standing necessary to raise them.”

The decision underscored that the court, even with the recent addition of more conservative justices, at times is still able to find broad coalitions supporting middle-ground outcomes in hot-button cases.

Joining the majority were Chief Justice John Roberts and Justices Clarence Thomas, Sonia Sotomayor, Elena Kagan, Brett Kavanaugh and Amy Coney Barrett.

Justice Barrett had been a focal point after Democrats made the ACA case a central plank of their opposition to her confirmation last October. The court heard arguments in the case two weeks after she took the bench, and the justices’ comments during that session signaled they were unlikely to strike down the law.

The ruling marked what could be the end of the line for major legal challenges to the health law, which has been a top target for conservative lawyers for more than a decade.

“With millions of people relying on the Affordable Care Act for coverage, it remains, as ever, a BFD. And it’s here to stay,” President Biden tweeted after the decision, using an abbreviation for big freaking deal, in the more-polite version. He also encouraged more participation in the insurance programs provided under the act.

In dissent, Justice Samuel Alito, joined by Justice Neil Gorsuch, accused the majority of ducking the constitutional issues that conservatives for years have argued make the federal healthcare overhaul unconstitutional.

“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,” Justice Alito wrote. “In all three episodes, with the Affordable Care Act facing a serious threat, the court has pulled off an improbable rescue.”

‘In all three episodes, with the Affordable Care Act facing a serious threat, the court has pulled off an improbable rescue’

— Justice Samuel Alito, in dissent

Texas Republican Attorney General Ken Paxton, now in the middle of a re-election campaign, led the GOP challengers. “Attorney General Paxton will continue to fight this law—in fact, he has only just begun,” a campaign spokesman said.

GOP lawmakers in Washington signaled they would advocate for legislative changes after the latest court setback.

“The ruling does not change the fact that Obamacare failed to meet its promises and is hurting hard-working American families,” House Minority Leader Kevin McCarthy (R., Calif.) and other top Republicans said in a statement. “Now, Congress must work together to improve American health care.”

The latest health-law legal battle has been a cloud over the ACA for several years. A Texas federal judge ruled in 2018 that the entire law was invalid, a decision that never went into effect. A year later a federal appeals court agreed that the insurance mandate was unconstitutional but ordered the trial court to reconsider whether other parts of the sprawling law could remain in place.

The high court’s decision reversed those rulings. Had the justices voided the ACA, their decision could have forced a reset of federal healthcare policy and thrown the marketplace into turmoil, while also potentially leading to a considerable increase in uninsured Americans.

Justice Breyer, writing for the court, said the challengers didn’t come close to showing that they had been harmed by Congress’s decision not to penalize people for not carrying insurance.

Two individual plaintiffs who joined the Republican-led states’ lawsuit are in no legal jeopardy if they don’t buy insurance, because the government now has no means to enforce the insurance mandate, he said. The states argued that the zeroing out of the tax penalty actually imposed costs on them, but the court said those claims were illogical and unsupportable.

To allow plaintiffs to proceed with lawsuits when they face no harms “would threaten to grant unelected judges a general authority to conduct oversight of decisions of the elected branches of government,” Justice Breyer wrote.

About 31 million people have coverage because of the ACA, according to the Biden administration. That number includes about 11.3 million people who have plans purchased on the ACA exchange and 14.8 million who have obtained coverage under the law’s expansion of Medicaid.

The court’s ruling provides a boost for Mr. Biden and Democrats, who have called for making recent expansions of the ACA permanent. It may also spur ACA sign-ups since a special open-enrollment period under the law is currently under way.

‘It’s eventually going to be pretty hard to unravel from the system’

— Sen. Roy Blunt (R., Mo.), of the Affordable Care Act

Congress in March passed legislation providing a two-year expansion in health-insurance premium subsidies that lowered payments for consumers and removed an income cap limiting who is eligible for tax credits for purchasing coverage.

Some Republicans signaled defeat in their decadelong effort to undo former President Barack Obama’s signature legislative achievement.

“Well, the Affordable Care Act gets constantly woven deeper and deeper into the system,” said Sen. Roy Blunt (R., Mo.). “It’s eventually going to be pretty hard to unravel from the system. The court had a chance to do that today and didn’t do it.”

A group of Democratic state attorneys general had intervened in the case, California v. Texas, to defend the law against arguments made by their Republican counterparts and the Trump administration, which abandoned a defense of the ACA. Xavier Becerra, then California’s attorney general, led the effort, and his work on the case helped propel him to a prominent role in the Biden administration, where he now leads the Department of Health and Human Services.

“It’s the exclamation point we needed,” Mr. Becerra said of the ruling.

‘It’s the exclamation point we needed’

— Xavier Becerra, Secretary of Health and Human Services, of the ruling

Not all Republican officials supported the lawsuit’s attempt to void the whole law.

“This lawsuit was an invitation to judicial activism from the start, and while SCOTUS never reached the constitutional issues, I am happy that its decision did no harm to our people,” said Ohio Attorney General Dave Yost. He had filed a brief urging the high court to preserve most of the ACA, including protections for people with pre-existing conditions.

Healthcare industry officials, including hospital and insurance groups, generally greeted the decision with relief.

In addition to the mandate that most people carry health insurance, the Affordable Care Act barred insurers from denying coverage—or charging more—to people with existing health conditions. It also expanded the availability of Medicaid coverage for limited-income Americans and allowed young adults to stay on their parents’ plans until they turned 26.

The ACA contains hundreds of other provisions, on everything from contraception and vaccine coverage to healthcare fraud and nutritional labeling on restaurant menus.

A divided Supreme Court previously upheld the mandate in a 2012 decision, based on Congress’s power to levy taxes. Former President Donald Trump made opposition to the Affordable Care Act a cornerstone of his agenda, but Republicans failed to repeal the law during his term.

Instead, lawmakers in 2017 reduced the penalty to $0 as part of Republicans’ tax overhaul package. And the GOP-led states argued that the change meant the mandate could no longer be upheld under the taxing power—or any other provision of the Constitution.

In early defenses of the law, the Obama administration’s solicitor general, Donald Verrilli, Jr., had argued the mandate was essential, a way to ensure that more healthy people bought policies that effectively subsidized those requiring care. But at Supreme Court arguments in November, Mr. Verrilli, now representing the House of Representatives, said that experience had shown the health insurance exchanges created by the act could function through voluntary participation.

The Supreme Court’s other ACA ruling came in 2015, when a 6-3 court ruled that subsidized insurance policies could lawfully remain available to lower-income Americans nationwide. That decision rejected arguments that the wording of the law didn’t allow the subsidies in the many states that didn’t set up their own exchanges.

Write to Brent Kendall at brent.kendall@wsj.com, Jess Bravin at jess.bravin+1@wsj.com and Stephanie Armour at stephanie.armour@wsj.com

Corrections & Amplifications
The Supreme Court preserved the Affordable Care Act for the third time with its decision. An earlier headline erroneously said it was the first time the high court had preserved the law. (Corrected on June 17.)