WASHINGTON — The Supreme Court ruled Monday that the federal government must live up to its promise to shield insurance companies from some of the risks they took in participating in the exchanges established by President Barack Obama’s health care law, the Affordable Care Act.

Justice Sonia Sotomayor, writing for the majority in the 8-to-1 ruling, said the court’s decision vindicated “a principle as old as the nation itself: The government should honor its obligations.”

The health care law had promised the insurers that they would be protected, she wrote, and it did not matter that Congress later failed to appropriate money to cover the insurers’ shortfalls.

The Affordable Care Act established so-called risk corridors meant to help insurance companies cope with the risks they took when they decided to participate in the law’s marketplaces without knowing who would sign up for coverage. Under the program, the federal government would limit insurance companies’ gains and losses on insurance sold in the marketplaces from 2014 through 2016.