The United States Supreme Court on Thursday upheld the $1 trillion Affordable Care Act and its requirement that every American purchase health insurance coverage.

The 5-4 decision was handed down as hundreds of people gathered on the Supreme Court steps, hoisting signs, flags and bullhorns expressing either support or opposition to the health care law.

(View the Supreme Court's ruling)

The ruling appeared to surprise many opponents of the law who were predicting the court would at least find the individual mandate requiring people to buy insurance to be unconstitutional. Instead, the court ruled that while the mandate couldn't be upheld under the commerce clause, as the Obama administration claimed, it could be declared constitutional as a tax.

Chief Justice John Roberts sided with the majority and wrote the opinion.

The court also ruled that the health care law's planned massive expansion of Medicaid for everyone below 133 percent over the poverty level is constitutional, but that the federal government may not punish states by withholding their current levels of Medicaid funding if they refuse to expand the program.

(See more photos from the Supreme Court)

Justice Anthony Kennedy wrote the dissenting opinion, arguing that the law "is invalid in its entirety."

The decision comes days after Republican leaders, expecting the law to be struck down, warned their rank-and-file against "spiking of the ball" in celebrating its defeat.

Instead, it was the Democrats who were celebrating.

“This decision is a victory for the American people," House Minority Leader Nancy Pelosi, D-Calif., one of the law's chief architects, said. "With this ruling, Americans will benefit from critical patient protections, lower costs for the middle class, more coverage for families, and greater accountability for the insurance industry."

As Republican lawmakers huddled to craft their own response, conservative groups were ready with a reaction.

The Club for Growth called the ruling, "unfortunate," and called on the GOP to press ahead with legislative efforts to repeal the reforms.

Republicans have already pledged to repeal the law, and the ruling may fuel their campaign message that the Democrats need to be voted out of office to prevent the health care law from being fully enacted.

"Today’s decision does nothing to diminish the fact that Obamacare’s mandates, tax hikes, and Medicare cuts should be repealed and replaced with common sense reforms that lower costs and that the American people actually want," Senate Minority Leader Mitch McConnell, R-Ky., said. "It is my hope that with new leadership in the White House and Senate, we can enact these step-by-step solutions and prevent further damage from this terrible law.”

The reaction in front of the courthouse evolved from confusion into anger for those who were counting on the law being struck down.

One woman grabbed bullhorn and shouted a message to the Internal Revenue Service. "We will not comply with this unconstitutional tax, so you may as well come over and get me now, because I ain't paying."

Another group of opponents changed "We will not comply."