The justices said in a 6-3 ruling that the subsidies that 8.7 million people currently receive to make insurance affordable do not depend on where they live, as opponents contended.
The outcome was the second major victory for Obama in politically charged Supreme Court tests of his most significant domestic achievement. And it came the same day the court gave him an unexpected victory by preserving a key tool the administration uses to fight housing bias.
Obama greeted news of the decision by declaring the health care law "is here to stay." He said the law is no longer about politics, but the benefits millions of people are receiving.
Declining to concede, House Speaker John Boehner of Ohio said Republicans, who have voted more than 50 times to undo the law, will "continue our efforts to repeal the law and replace it with patient-centered solutions that meet the needs of seniors, small business owners, and middle-class families."
At the court, Chief Justice John Roberts again voted with his liberal colleagues in support of the law. Roberts also was the key vote to uphold it in 2012. Justice Anthony Kennedy, a dissenter in 2012, was part of the majority on Thursday.
"Congress passed the Affordable Care Act to improve health insurance markets, not to destroy them," Roberts declared in the majority opinion.
Limiting the subsidies only to individuals in states with their own exchanges could well push insurance markets in the other states "into a death spiral," Roberts wrote.
Justice Antonin Scalia, in a dissent he summarized from the bench, strongly disagreed. "We should start calling this law SCOTUScare," he said, using an acronym for the Supreme Court and suggesting his colleagues' ownership by virtue of their twice stepping in to save the law from what he considered worthy challenges.
His comment drew a smile from Roberts, his seatmate and the object of Scala's ire.
Scalia said that Roberts' 2012 decision that upheld the law and his opinion on Thursday "will publish forever the discouraging truth that the Supreme Court of the United States favors some laws over others, and is prepared to do whatever it takes to uphold and assist its favorites."
Justices Samuel Alito and Clarence Thomas joined the dissent, as they did in 2012.
Nationally, 10.2 million people have signed up for health insurance under the Obama health overhaul. That includes the 8.7 million people who are receiving an average subsidy of $272 a month to help pay their insurance premiums.
Of those receiving subsidies, 6.4 million were at risk of losing that aid because they live in states that did not set up their own health insurance exchanges.
The health insurance industry breathed a big sigh of relief, and a national organization representing state regulators from both political parties said the court's decision will mean stable markets for consumers.
"This decision allows (state officials) to move forward with a level of confidence that their markets will not see significant disruption due to a paradigm shift," said Ben Nelson, CEO of the National Association of Insurance Commissioners and a former Democratic senator from Nebraska.
Shares of publicly traded hospital operators including HCA Holdings Inc. and Tenet Healthcare Corp. soared after the ruling relieved those companies of the prospect of having to deal with an influx of uninsured people. Investors had worried that many patients would drop their coverage if they no longer had tax credits to help pay.
The challenge devised by die-hard opponents of the law relied on four words — "established by the state" — in the more than 900-page law.
The law's opponents argued that the vast majority of people who now get help paying for their insurance premiums are ineligible for their federal tax credits. That is because roughly three dozen states opted against creating their own health insurance marketplaces, or exchanges, and instead rely on the federal healthcare.gov to help people find coverage if they don't get insurance through their jobs or the government.
In the challengers' view, the phrase "established by the state" demonstrated that subsidies were to be available only to people in states that set up their own exchanges.
The administration, congressional Democrats and 22 states responded that it would make no sense to construct the law the way its opponents suggested. The idea behind the law's structure was to decrease the number of uninsured. The law prevents insurers from denying coverage because of "pre-existing" health conditions. It requires almost everyone to be insured and provides financial help to consumers who otherwise would spend too much of their paycheck on their premiums.
The point of the last piece, the subsidies, is to keep enough people in the pool of insured to avoid triggering a disastrous decline in enrollment, a growing proportion of less healthy people and premium increases by insurers.
Several portions of the law indicate that consumers can claim tax credits no matter where they live. No member of Congress said that subsidies would be limited, and several states said in a separate brief to the court that they had no inkling they had to set up their own exchange for their residents to get tax credits.
The 2012 case took place in the midst of Obama's re-election campaign, when Obama touted the largest expansion of the social safety net since the advent of Medicare nearly a half-century earlier. But at the time, the benefits of the Affordable Care Act were mostly in the future. Many of its provisions had yet to take effect.
In 2015, the landscape has changed, although the partisan and ideological divisions remain for a law that passed Congress in 2010 with no Republican votes.
The case is King v. Burwell, 14-114.