Republicans had hoped that the newly conservative court would rule in their favor.
The ruling in the case, California v. Texas, was 7-2.
The ruling came in a lawsuit by Texas and 17 other Republican-governed states and later joined by Trump's administration.
The Affordable Care Act, the public health care system signed into law by President Barack Obama, survived a legal challenge Thursday when the Supreme Court ruled that it can not be struck down on the basis of the elimination of the individual mandate. The decision was authored by liberal Justice Stephen Breyer. A coalition of 20 states including Democratic-governed California and NY and the Democratic-controlled House of Representatives intervened in the case to try to preserve Obamacare after Trump refused to defend the law.
The 7-2 ruling leaves the Obama-era healthcare law intact and preserves healthcare coverage for millions of Americans. "We need to build on the Affordable Care Act and continue to strengthen and expand it".
The provision, called the "individual mandate", required Americans to obtain health insurance or pay a financial penalty. It also expanded the availability of Medicaid coverage for limited-income Americans and allowed young adults to stay on their parents' plans until they turned 26.
After Texas and other states sued, a coalition of 20 states including Democratic-governed California and NY and the Democratic-controlled House of Representatives intervened in the case to try to preserve Obamacare after Trump refused to defend the law.
In addition to the mandate that most people carry health insurance, the Affordable Care Act barred insurers from denying coverage-or charging more-to people with existing health conditions. Justices Samuel Alito and Gorsuch dissented. "Fans of judicial inventiveness will applaud once again", Alito said.
A divided Supreme Court previously upheld the mandate in a 2012 decision, based on Congress's power to levy taxes.
"Thanks to the tireless advocacy of Americans across the country and the work of Democrats in Congress, the Affordable Care Act endures", said Nancy Pelosi, the Democratic speaker of the House of Representatives.
Today's ruling means the healthcare of millions will remain protected, saving the United States between $150 billion and $350 billion over the next decade.
Republicans fiercely opposed Obamacare when it was proposed, failed to repeal it when they controlled both chambers of Congress and have been unsuccessful in getting courts to invalidate the law, which was Democratic former president Barack Obama's signature domestic policy achievement.
Opposition to Obamacare seems to have receded as a political issue for Republicans as the party has emphasized other matters such as immigration, voting restrictions and hot-button cultural issues.
Opponents of the Affordable Care Act argued that because the penalty is now $0, the provision in the law that requires everyone to buy insurance is no longer valid.
The impetus for the Supreme Court case was a 2018 ruling by a federal judge in Texas that Obamacare as structured following the 2017 change violated the Constitution and was invalid in its entirety.