The Supreme Court ruled on Monday that the government has to pay a $12 billion debt owed to insurance companies that participated in a program that existed in the first years of the Affordable Care Act, the health-care overhaul law known as Obamacare.

The court voted 8-1 to allow insurance companies to seek payments owed to them via Obamacare's "risk corridors" program, which aimed to limit the risk insurance companies faced when signing onto online health-care exchanges in their first years of operation.

The 2010 law called for the Department of Health and Human Services to pay insurers who suffered losses under the program between 2014 and 2016, while taking payments from those that made large profits.

The program never took in as much money as it was required to pay out, leading Republicans to liken it to a "bailout fund" for insurers. In 2014, the program owed nearly $3 billion to insurers, while it was only entitled to about $360 million. In 2015, the deficit was $5.5 billion. In 2016, the deficit was nearly $4 billion.

Republicans, who have fought against Obamacare since its inception, inserted language into appropriations legislation starting in 2014 that restricted HHS' ability to use funding to make the risk corridor payments. Citing that language, a federal appeals court had repeatedly ruled in the government's favor, against the insurers.

But the Supreme Court rejected that reasoning.

Justice Sonia Sotomayor wrote that the congressional riders "neither repealed nor discharged" the government's obligation to pay. By failing to appropriate money for debts already owed, "Congress simply did that and no more."

"These holdings reflect a principle as old as the Nation itself: The Government should honor its obligations," the Obama appointee wrote.

In dissent, Justice Samuel Alito wrote that the majority opinion "has the effect of providing a massive bailout for insurance companies that took a calculated risk and lost."

Alito wrote that he would have scheduled the case to be reargued next term, with a focus on when individuals and corporations are permitted to seek damages from the government.

The case, known as Maine Community Health Options v. United States, is separate from another case over Obamacare that the justices have agreed to hear next term. In that case, a coalition of red states and the Trump administration have asked the court to declare the entire law unconstitutional.