The top court voted 7-2 to reverse an appeals court ruling that had struck down the law's individual mandate provision.
Two of former President Donald Trump's court picks, Justices Brett Kavanaugh and Amy Coney Barrett, joined the majority in rejecting the Republican effort.
President Joe Biden praised the ruling as a major victory and vowed to expand Obamacare.
The Supreme Court ruled 7-2 on Thursday against Texas and other Republican-led states seeking to strike down Obamacare in the law's latest test before the nation's highest court.
The court reversed an appeals court ruling that had struck down the law's individual mandate provision. Chief Justice John Roberts and fellow conservative Justices Clarence Thomas, Brett Kavanaugh and Amy Coney Barrett joined Justice Stephen Breyer's opinion, as did Sonia Sotomayor and Elena Kagan.
Breyer said Texas and the other states that challenged the law failed to show they were harmed by it.
"Neither the individual nor the state plaintiffs have shown that the injury they will suffer or have suffered is 'fairly traceable' to the 'allegedly unlawful conduct' of which they complain," Breyer wrote.