WASHINGTON — The Supreme Court on Thursday upheld the vast majority of President Barack Obama’s historic health care overhaul, including the hotly debated core requirement that virtually all Americans have health insurance.

The 5-4 decision means the huge overhaul, still taking effect, will proceed and pick up momentum over the next several years, affecting the way that countless Americans receive and pay for their personal medical care.

The ruling hands Obama a campaign-season victory in rejecting arguments that Congress went too far in approving the plan. However, Republicans quickly indicated they will try to use the decision to rally their supporters against what they call “Obamacare.”

“While no legislation is perfect, more people will now have access to affordable health insurance, and that is a good development for patients and the hospitals that serve them,” said Arizona Hospital and Healthcare Association President and Chief Executive Officer Laurie Liles. “This is a pivotal time in our history, and hospitals are transforming the way healthcare is delivered, making care safer and more affordable for patients,” she said. “Arizona hospital leaders look forward to partnering with policymakers to achieve the goals of better care, better health and lower costs.”

Stocks of hospital companies rose sharply, and insurance companies fell immediately after the decision was announced that Americans must carry health insurance or pay a penalty.

Breaking with the court’s other conservative justices, Chief Justice John Roberts announced the judgment that allows the law to go forward with its aim of covering more than 30 million uninsured Americans.

The justices rejected two of the administration’s three arguments in support of the insurance requirement. But the court said the mandate can be construed as a tax. “Because the Constitution permits such a tax, it is not our role to forbid it, or to pass upon its wisdom or fairness,” Roberts said.

The court found problems with the law’s expansion of Medicaid, but even there said the expansion could proceed as long as the federal government does not threaten to withhold states’ entire Medicaid allotment if they don’t take part in the law’s extension.

“Now that the Supreme Court has removed the uncertainty surrounding the constitutionality of the Affordable Care Act, it’s time for employers to get to work,” said Sheldon Blumling, an attorney with Fisher & Phillips, a national labor and employment law firm that represents employers. Blumling, an employee benefits attorney who counsels clients on how to comply with the law, continued by saying: “Employers must focus on how the employer “play or pay” mandate and other aspects of the law will impact their plan design and costs beginning in 2014. In addition to the long-term strategic concerns for employers, there are numerous new compliance obligations that must be addressed immediately. In the next 18 to 24 months, employers will be extremely busy getting their healthcare houses in order.”

The court’s four liberal justices, Stephen Breyer, Ruth Bader Ginsburg, Elena Kagan and Sonia Sotomayor, joined Roberts in the outcome.

Justices Samuel Alito, Anthony Kennedy, Antonin Scalia and Clarence Thomas dissented.

Kennedy summarized the dissent in court. “In our view, the act before us is invalid in its entirety,” he said.

The dissenters said in a joint statement that the law “exceeds federal power both in mandating the purchase of health insurance and in denying non-consenting states all Medicaid funding.”

In all, the justices spelled out their views in six opinions totaling 187 pages. Roberts, Kennedy and Ginsburg spent 57 minutes summarizing their views in the packed courtroom.

The legislation passed Congress in early 2010 after a monumental struggle in which all Republicans voted against it. House Majority Leader Eric Cantor, R-Va., said Thursday the House will vote the week of July 9 on whether to repeal the law, though such efforts have virtually no chance in the Democratic-controlled Senate.

GOP presidential candidate Mitt Romney has joined in calls for complete repeal.

After the ruling, Republican campaign strategists said Romney will use it to continue campaigning against “Obamacare” and attacking the president’s signature health care program as a tax increase.

“Obama might have his law, but the GOP has a cause,” said veteran campaign adviser Terry Holt. “This promises to galvanize Republican support around a repeal of what could well be called the largest tax increase in American history.”

Democrats said Romney, who backed an individual health insurance mandate when he was Massachusetts governor, will have a hard time exploiting the ruling.

“Mitt Romney is the intellectual godfather of Obamacare,” said Democratic consultant Jim Manley. “The bigger issue is the rising cost of health care, and this bill is designed to deal with it.”

More than eight in 10 Americans already have health insurance. But for most of the 50 million who are uninsured, the ruling offers the promise of guaranteed coverage at affordable prices. Lower-income and many middle-class families will be eligible for subsidies to help pay premiums starting in 2014.

There’s also an added safety net for all Americans, insured and uninsured. Starting in 2014, insurance companies will not be able to deny coverage for medical treatment, nor can they charge more to people with health problems. Those protections, now standard in most big employer plans, will be available to all, including people who get laid off, or leave a corporate job to launch their own small business.

Seniors also benefit from the law through better Medicare coverage for those with high prescription costs, and no copayments for preventive care. But hospitals, nursing homes, and many other service providers may struggle once the Medicare cuts used to finance the law really start to bite.

Illegal immigrants are not entitled to the new insurance coverage under the law, and will remain one of the biggest groups uninsured.

Obama’s law is by no means the last word on health care. Experts expect costs to keep rising, meaning that lawmakers will have to revisit the issue perhaps as early as next year, when federal budget woes will force them to confront painful options for Medicare and Medicaid, the giant federal programs that cover seniors, the disabled, and low-income people.

The health care overhaul focus will now quickly shift from Washington to state capitals. Only 14 states, plus Washington, D.C., have adopted plans to set up the new health insurance markets called for under the law. Called exchanges, the new markets are supposed to be up and running on Jan. 1, 2014. People buying coverage individually, as well as small businesses, will be able to shop for private coverage from a range of competing insurers.

Most Republican-led states, including large ones such as Texas and Florida, have been counting on the law to be overturned and have failed to do the considerable spade work needed to set up exchanges. There’s a real question about whether they can meet the deadline, and if they don’t, Washington will step in and run their exchanges for them.

In contrast to the states, health insurance companies, major employers, and big hospital systems are among the best prepared. Many of the changes called for in the law were already being demanded by employers trying to get better value for their private health insurance dollars.

“The main driver here is financial,” said Dr. Toby Cosgrove, CEO of the Cleveland Clinic, which has pioneered some of the changes. “The factors driving health care reform are not new, and they are not going to go away.”

Justice Ginsburg said the court should have upheld the entire law as written without forcing any changes in the Medicaid provision. She said Congress’ constitutional authority to regulate interstate commerce supports the individual mandate. She warned that the legal reasoning, even though the law was upheld, could cause trouble in future cases.

“So in the end, the Affordable Health Care Act survives largely unscathed. But the court’s commerce clause and spending clause jurisprudence has been set awry. My expectation is that the setbacks will be temporary blips, not permanent obstructions,” Ginsburg said in a statement she, too, read from the bench.

For more information on the new health care law, visit The White House’ website at whitehouse.gov/healthreform.