WASHINGTON -- The individual health insurance mandate is constitutional, the Supreme Court ruled Thursday, upholding the central provision of President Barack Obama's signature Affordable Care Act.

The controlling opinion, written by Chief Justice John Roberts, upheld the mandate as a tax, although concluded it was not valid as an exercise of Congress' commerce clause power. Justices Ruth Bader Ginsburg, Stephen Breyer, Sonia Sotomayor and Elena Kagan joined in the outcome.

The decision in National Federation of Independent Business v. Sebelius comes as something of a surprise after the generally hostile reception the law received during the six hours of oral arguments held over three days in March. But by siding with the court's four Democratic appointees, Chief Justice Roberts avoided the delegitimizing taint of politics that surrounds a party-line vote while passing Obamacare's fate back to the elected branches. GOP candidates and incumbents will surely spend the rest of the 2012 campaign season running against the Supreme Court and for repeal of the law.

Five justices concluded that the mandate, which requires virtually all Americans to obtain minimum health insurance coverage or pay a penalty, falls within Congress' power under the Constitution to "lay and collect taxes."

"The individual mandate cannot be upheld as an exercise of Congress's power under the Commerce Clause," Roberts wrote. "That Clause authorizes Congress to regulate interstate commerce, not to order individuals to engage in it. In this case, however, it is reasonable to construe what Congress has done as increasing taxes on those who have a certain amount of income, but choose to go without health insurance. Such legislation is within Congress's power to tax."

Ginsburg, writing separately for the four liberals, said they would have upheld the mandate under the commerce clause too. "Unlike the market for almost any other product or service, the market for medical care is one in which all individuals inevitably participate," she wrote. "Virtually every person residing in the United States, sooner or later, will visit a doctor or other health care professional."

Justices Antonin Scalia, Anthony Kennedy, Clarence Thomas and Samuel Alito joined in a dissent. Together, Roberts' controlling opinion, Ginsburg's concurrence, the four-justice dissent and Thomas' own dissent add up to 187 pages.

In a nod to the importance of the health care cases, Roberts, Ginsburg and Kennedy all chose to read summaries of their opinions from the bench.

In a section of his opinion joined by the liberal justices, Roberts noted that the conservative dissenters contend that the mandate cannot be upheld as a tax "because Congress did not 'frame' it as such. In effect, they contend that even if the Constitution permits Congress to do exactly what we interpret this statute to do, the law must be struck down because Congress used the wrong labels."

But the majority was not persuaded by that argument. Roberts wrote that the mandate provision "need not be read to do more than impose a tax. That is sufficient to sustain it."

On Medicaid expansion, the court upheld the expansion but with a critical caveat: The federal government may not threaten the states that don't comply with the loss of their existing funding. Essentially, the Medicaid expansion is now optional for the states.

"As for the Medicaid expansion, that portion of the Affordable Care Act violates the Constitution by threatening existing Medicaid funding," Roberts wrote. "Congress has no authority to order the States to regulate according to its instructions. Congress may offer the States grants and require the States to comply with accompanying conditions, but the States must have a genuine choice whether to accept the offer. The States are given no such choice in this case: They must either accept a basic change in the nature of Medicaid, or risk losing all Medicaid funding. The remedy for that constitutional violation is to preclude the Federal Government from imposing such a sanction."

For their part, the dissenters were not impressed with Roberts' parsing of the law. "The Court regards its strained statutory interpretation as judicial modesty. It is not. It amounts instead to a vast judicial overreaching," wrote the four other conservatives.

They then looked to the political future: The majority's decision, they argued, "creates a debilitated, inoperable version of health-care regulation that Congress did not enact and the public does not expect. It makes enactment of sensible health-care regulation more difficult, since Congress cannot start afresh but must take as its point of departure a jumble of now senseless provisions, provisions that certain interests favored under the Court’s new design will struggle to retain. And it leaves the public and the States to expend vast sums of money on requirements that may or may not survive the necessary congressional revision."

Summarizing his delicate decision from the bench, Roberts reminded his listeners that it is "not our job to save the people from the consequences of their political choices." Still, the decision appeared to do just that.

By narrowing Congress' commerce and spending powers, Roberts moved the law in a decidedly conservative direction. Yet by invoking the taxing power, he saved not only the people but also Congress, the president and the Supreme Court itself from the consequences of their political choices that had seemed so evident at oral argument three months ago.

Careful legal parsing aside, the bottom line is: The Affordable Care Act has survived.

HuffPost readers: How will the Supreme Court's Affordable Care Act ruling affect your family? Tell us: offthebus@huffingtonpost.com (include your phone number if you are willing to be interviewed).

Erin Mershon contributed to this report.