Hospitals will gain millions of paying customers. Insurers, by contrast, could face crimped profits from restrictive rules. Medical device and pharmaceutical companies will bear new taxes and other higher payouts, but they were already expecting such costs.


That, at least, was the immediate view of the impact of the Supreme Court’s ruling Thursday that upheld the nation’s health care overhaul.


It was also a view shared by stock market investors. Hospital stocks rose, with HCA gaining about 11 percent and Tenet Healthcare rising 5 percent. Stocks of insurers like WellPoint, however, lost as much as 5 percent. Some medical device and pharmaceutical stocks had slight declines.


For hospitals, the good news is that the law, which is aimed at extending insurance coverage to more than 30 million people, was upheld.


That will mean fewer uninsured people streaming into their emergency rooms receiving treatment for which they cannot pay.


But executives and analysts say that the Supreme Court decision, and the law itself, are not unalloyed benefits for hospitals. “It’s a huge exaggeration to say just because of today’s action that everything is going to be nice and rosy going forward,” said Michael Dowling, the chief executive of the nonprofit North Shore-Long Island Jewish Health System.


Executives and analysts say that the law will reduce Medicare payments for hospital services. For some hospitals, like MemorialCare Health System, a six-hospital chain in Southern California, those cuts more than offset any potential gains from newly insured patients, said Barry Arbuckle, its chief executive.


Moreover, the Supreme Court ruled Thursday that the federal government could not withhold certain payments from states that refuse to participate in an expansion of Medicaid. The Medicaid expansion, which was expected to account for at least half of the newly covered people, now will be a choice for states rather than a requirement.


The government “has lost its stick,” said Sheryl Skolnick, an analyst at CRT Capital. “There is a risk here that the Medicaid expansion may not happen as hoped for by the hospital industry.”


Still, some executives said that there were carrots that could induce the states to go along, mainly the fact that the federal government would shoulder a majority of the cost of the expansion.


“The people who need this coverage aren’t going away,” said James G. Carlson, chief executive of Amerigroup, an insurance company that works mainly with Medicaid patients. He said that despite expected comments from some state officials opposing the Medicaid expansion, “We think most of them will come around to the idea that it probably makes pretty good sense.”


Investors seemed to agree. Amerigroup’s shares rose about 5 percent. A competitor, Molina Healthcare, rose about 9 percent.


Shares of commercial insurers like WellPoint and Aetna largely fell. Those insurance companies avoided what had been considered a bad outcome: a decision that threw out the individual mandate to buy health insurance but kept intact the requirements that insurers cover patients with pre-existing conditions and charge sick patients the same as healthy ones. That, they said, would have forced them to pay for the law’s expensive elements without the influx of healthy customers the mandate was designed to bring in.


Still, some investors had apparently been hoping that the law would be tossed out in its entirety, relieving insurers of restrictions like a requirement to spend a certain percentage of the premiums they collect on medical treatments.


“This was a bill that passed with an onerous set of restrictions on how the industry could operate, and the Supreme Court confirmed that this is going to be the lay of the land,” Joshua Raskin, an insurance industry analyst at Barclays, said in an interview.


The stock decline surprised Robert Laszewski, a health industry consultant, who said the law was a known quantity and the result of bargaining between industry executives, including those in the insurance industry, and politicians.


The decision does allow insurers to seek new customers. Cigna, for example, has recently begun a push into providing coverage for individuals. “We see it as an attractive growth market,” David Cordani, Cigna’s chief executive, said Thursday.


Indeed, as the day wore on, some of the stocks of health insurers began to recover, with UnitedHealth Group and Humana actually finishing the day slightly higher.


Under the law, pharmaceutical companies are paying new taxes, additional Medicaid rebates and subsidies to close the Medicare drug coverage “doughnut hole.” But investors and companies had already factored in these costs, so the upholding of the law preserved the status quo.


“Much ado about nothing,” Matthew Roden, biotechnology analyst at UBS, said in a note Thursday.


Had the law been struck down, however, analysts had expected that drug company earnings would have risen in the short term.


Medical device companies will have to pay a new 2.3 percent tax on sales starting in January to help pay for the new law. The House of Representatives recently voted to repeal the tax, but the prospect of such legislation passing the Senate is uncertain.


Device companies and their representatives say the tax will impede innovation and cost jobs. But the new health care law will not bring device companies many new customers because many of the newly covered individuals will be young.


“Most of them are not getting knee replacements and hip replacements and a lot of things you see in the device world,” said Mary Grealy, president of the Healthcare Leadership Council, a trade association representing chief executives of various sectors in the health care industry.