The court upheld a core requirement known as the "individual mandate" that Americans buy insurance or pay a fine.
Challengers said Congress could not force people to buy goods from private companies. The government said health insurance was unlike any other product.
Healthcare is a deeply polarising issue in the US and Republicans strongly opposed Mr Obama's legislation.
In addition to the individual mandate, the Supreme Court was asked consider another part of the law that deals with the expansion of Medicaid, a government healthcare programme for low-income citizens.
The court ruled to limit that provision but did not strike it down altogether.
The Chief Justice, John Roberts, who is seen as a conservative, voted in favour of the healthcare law along with four liberal justices on the bench to provide the deciding vote in the case.
The Supreme Court is composed of nine justices, five are seen as conservative justices and four as liberals.