The US Supreme Court has dismissed the latest Republican challenge to the Affordable Care Act, preserving Barack Obama’s flagship healthcare reforms in a major win for Democrats.

In a 7-2 opinion released on Thursday, the nine-member court denied an attempt to invalidate the sweeping Affordable Care Act, which has provided health coverage for tens of millions of previously uninsured Americans.

Stephen Breyer wrote the majority opinion, joined by two other liberals, Sonia Sotomayor and Elena Kagan, as well as four conservatives: chief justice John Roberts, Clarence Thomas, Brett Kavanaugh and Amy Coney Barrett. Samuel Alito dissented, joined by fellow conservative Neil Gorsuch.

Thursday’s decision marked the third time that the nation’s highest court has rebuffed challenges to the ACA, following rulings in 2012 and 2015. The latest case was brought by a group of 18 states led by Texas and two individuals. Donald Trump’s White House had filed an amicus brief in support of the plaintiffs.

The plaintiffs had taken aim at the controversial “individual mandate” that originally required all Americans to have health insurance or pay a financial penalty.

In its 2012 decision upholding the ACA, the Supreme Court held that the penalty for not having insurance could be characterised as a tax, making it a constitutional use of Congress’s powers.

However, Congress later reduced the penalty to zero. The Texas-led plaintiffs sued, arguing that the mandate was no longer constitutional, and the entire law should be struck down.

But the majority found that the plaintiffs had suffered no harm that would give them grounds to sue.

“To have standing, a plaintiff must ‘allege personal injury fairly traceable to the defendant’s allegedly unlawful conduct and likely to be redressed by the requested relief,’” Breyer wrote. “No plaintiff has shown such an injury ‘fairly traceable’ to the ‘allegedly unlawful conduct’ challenged here.”

The decision in California vs Texas is among the first high-profile rulings since Barrett joined the bench last October, tipping the balance of the nation’s highest court, 6-3, in favour of jurists appointed by Republican presidents.

Some progressives have in recent weeks called for Breyer, who at 82 is the oldest justice, to retire so Democratic president Joe Biden can nominate a liberal replacement while his party controls Congress. Supreme Court justices are nominated by presidents to lifetime appointments, but their nominations must be confirmed by a simple majority in the Senate.

Thursday’s ruling, however, underscored that the justices do not always rule along ideological lines. Just two Republican-appointed jurists, Alito and Gorsuch, opposed the decision.

“Today’s decision is the third instalment in our epic Affordable Care Act trilogy, and it follows the same pattern as instalments one and two,” Alito wrote in his dissent. “In all three episodes, with the Affordable Care Act facing a serious threat, the court has pulled off an improbable rescue.”

The ACA, often called “Obamacare”, was signed into law in 2010. The legislation divided public opinion but has become increasingly popular with American voters in recent years. It has withstood several legal challenges since its passage, as well as Republican-led efforts to repeal the law in Congress.

“After more than a decade of attacks on the Affordable Care Act through the Congress and the courts, today’s decision — the third major challenge to the law that the US. Supreme Court has rejected — it is time to move forward and keep building on this landmark law,” Biden said in a statement after the decision.

Nancy Pelosi, the Democratic speaker of the House of Representatives, called Thursday’s ruling “a landmark victory for Democrats’ work to defend protections for people with pre-existing conditions against Republicans’ relentless efforts to dismantle them”.

Her comments were echoed by Chuck Schumer, the Senate’s top Democrat, who vowed to build on the existing legislation. Democrats have called for an expansion of Medicaid — public health insurance for low-income Americans — among other healthcare reforms.

“Let me say definitively: the Affordable Care Act has won, the Supreme Court has ruled, the ACA is here to stay,” Schumer said.

Ron Klain, White House chief of staff, wrote on Twitter: “It’s still a BFD”, an apparent reference to a moment in 2010, when then vice-president Biden was heard whispering to Obama at the signing of the ACA into law: “This is a big fucking deal.”