The state of Florida, along with 12 other states, filed a legal challenge to the bill minutes after Mr Obama signed The Patient Protection and Affordable Care Act (ACA) into law in March 2010.

They were later joined by 13 more states, the National Federation of Independent Businesses and several individuals.

'Implement and improve'

Speaking afterwards, President Obama called the court's decision a victory for the country, saying people would not need to "hang their fortunes on chance" or fear financial ruin if they became sick.

"The highest court in the land has now spoken. We will continue to implement this law and we'll work together to improve on it where we can," Mr Obama said, speaking at the White House.

"What we won't do - what the country can't afford to do - is re-fight the political battles of two years ago or go back to the way things were. With today's announcement, it's time for us to move forward.

Analysis

By Mark MardellNorth America editor

This ruling means President Obama avoids a humiliating shellacking and does not have to make a near impossible decision about how to replace an eviscerated law. He can wipe his brow and breath a huge sigh of relief. But that does not mean it is bad news for Mitt Romney. The only way to get rid of the law is to elect him. He now has a cause that not only fires up his supporters but may also appeal to all important swing voters. It is, as he has said, a choice.

"We will be better off because we had the courage to pass this law," Mr Obama added.

On the Senate floor, he said the only way to fix the law was "full repeal".

Meanwhile, the Senate's Democratic majority leader, Harry Reid, disagreed: "Now that this matter is settled, let's move on to other things. Like jobs."

'Triggering a tax'

The mandate was eventually upheld by the justices, citing the taxation powers granted to Congress by the US constitution.

Who's uninsured?

Nearly 50 million, or 16.3% of Americans are uninsured

By ethnicity, the rate of those who lack insurance is

15.4% White

20.8% Black

18.1% Asian

30.7% Hispanic

Source: US Census Bureau

Chief Justice Roberts said: "We do not consider whether the Act embodies sound policies. That judgment is entrusted to the Nation's elected leaders.

"We ask only whether Congress has the power under the Constitution to enact the challenged provisions."

A majority of justices agreed that the penalty individuals must pay if they refuse to buy health insurance falls within Congress' power to levy taxes, upholding the "individual mandate".

"The mandate can be regarded as establishing a condition - not owning health insurance - that triggers a tax - the required payment to IRS," Justice Roberts wrote.

The government's main argument was that the law was legal under Congress' ability to regulate "interstate commerce" - but a majority of justices did not agree with this view.

Four dissenting justices said that limits on the power of Congress to regulate commerce and raise taxes "cannot be such as will enable the Federal Government to regulate all private conduct and to compel the States to function as administrators of federal programs."

"That clear principle carries the day here," they added.

In an opinion written by Justice Anthony Kennedy, the dissenting justices went further, to say: "In our view, the entire Act before us is invalid in its entirety."

Medicare clause limited

While the court described the penalty as a tax, it did not invoke a law that could have prevented the justices from ruling on the case.

Under a law called the Anti-Injunction Act, taxes cannot be legally challenged until after they have been levied. This could have delayed a verdict till 2015 - after the "individual mandate" comes into effect and the first round of penalties have been paid.

They were also not required to rule on the issue of "severability", which would determine whether other parts of the healthcare law could stand even if the mandate was struck down.

In addition to the individual mandate, the Supreme Court was asked to 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, saying Congress could place conditions on the use of federal funds.

"What Congress is not free to do is to penalize States that choose not to participate in that new program by taking away their existing Medicaid funding," the Supreme Court's opinion said.

Some hospital and health insurance stocks were trading higher in the wake of the Supreme Court's ruling.