This was challenging, he said, in light of the law’s “more than a few examples of inartful drafting,” a consequence of rushed work behind closed doors that “does not reflect the type of care and deliberation that one might expect of such significant legislation.”

But he said the law’s interlocking parts supported a ruling in favor of the subsidies, particularly given that a contrary decision could have given rise to chaos in the insurance markets. A ruling rejecting subsidies in most of the nation would have left in place other parts of the law, including its guarantee of coverage regardless of pre-existing conditions, its requirement that most Americans obtain insurance or pay a penalty, and its expansion of Medicaid.

Without the subsidies, many people would be unable to afford insurance, and healthier consumers would go without coverage, leaving insurers with a sicker, more expensive pool of customers. That would raise prices for everyone, leading to what supporters of the law called death spirals.

Image Copies of the court’s ruling in favor of nationwide health insurance subsidies were rushed to television news reporters. Credit... Doug Mills/The New York Times

“The statutory scheme compels us to reject petitioners’ interpretation,” Chief Justice Roberts wrote, referring to the challengers, “because it would destabilize the individual insurance market in any state with a federal exchange, and likely create the very ‘death spirals’ that Congress designed the act to avoid.”

In dissent, Justice Scalia wrote that the majority had stretched the statutory text too far.

“I wholeheartedly agree with the court that sound interpretation requires paying attention to the whole law, not homing in on isolated words or even isolated sections,” Justice Scalia wrote. “Context always matters. Let us not forget, however, why context matters: It is a tool for understanding the terms of the law, not an excuse for rewriting them.”

“Reading the act as a whole leaves no doubt about the matter,” he wrote. “ ‘Exchange established by the state’ means what it looks like it means.”