TORONTO - The Ontario government won an appeal Friday restoring a ban on private label generic drugs in an ongoing battle with Shoppers Drug Mart and other big pharmacy chains.

Two of three Court of Appeal judges hearing the case ruled that a divisional court went too far when it decided the province had no authority to ban pharmacies from substituting their own generic versions of name brands.

"On two occasions this court has strongly cautioned that in a major public policy domain involving the intersection of health care and public finance, courts must exhibit genuine restraint in reviewing statutes and regulations," wrote Justices James MacPherson and Andromache Karakatsanis.

"With respect, the divisional court did not show such restraint in the case."

The court battles reflect moves by the deficit-strapped Ontario government to cut health care costs as it struggles to balance its books over the next several years. The $16 billion provincial deficit has forced the government to review everything from soaring drug plan costs to public sector wages and financial transfers to restrain spending growth as the economy slows down,

In Friday's ruling, the appeal judges found that the lower court's analysis was too narrow, saying the regulations imposed by the government were not too harsh.

"Neither Shoppers nor Katz (another drug chain) is precluded from engaging in the purchase or sale of drugs in Ontario as long as they do so in accordance with the legislative and regulatory scheme," said the ruling.

"This is regulation; it is not a prohibition."

The court also said it agreed that the province could reasonably conclude private label generics would reduce competitiveness and drive up prices.

The province's Liberal government appealed the lower court ruling last February.

It was the latest salvo in a very public battle with the drug companies over a provincial move to disallow professional allowance fees that generic drug companies paid to the retail pharmacy chains for stocking their products.

Pharmacies said getting rid of those fees cost them an estimated $750 million a year in revenue and they have been looking for ways to get back money in other areas.

Shoppers (TSX:SC), Canada's largest drug store operator, said in a statement it was disappointed with the latest ruling.

The company said it was "in the process of reviewing the judgment and considering its options."

Health Minister Deb Matthews said challenging the February ruling was a necessary step to keep Ontario drug costs down, and was happy the decision had gone in the government's favour.

"Last year, our government successfully managed to bring down the cost of generic drugs for all Ontarians and we remain committed to ensuring that Ontarians receive their drugs at the best possible price," she said in a statement late Friday.

"It's the right thing to do."

The legal fight erupted after the province enacted regulations that stopped pharmacies such as Shoppers Drug Mart and Katz Group -- owner of the Rexall and PharmaPlus chains -- from selling their own lower-priced versions in place of popular name-brand drugs.

Shoppers was among a group of pharmacies that filed a legal challenge against the Ontario government last year.

On Feb. 3, the court ruled that the provincial government had no authority to ban pharmacies from substituting their own discount brand of prescription drugs for name brands.

Big pharmacies argue that private labelling allows them to cut costs by using their own version of the drugs rather than those bought from a manufacturer, but experts say it's unlikely they'll pass the savings on to customers.

Instead, the pharmacies were expected to use the extra revenue to recover profits that were lost when the so-called professional allowances -- or rebates --were banned.

BMO Capital Markets analyst Peter Sklar wrote in a research note that Shoppers stock price will probably take a hit from the Court of Appeal's decision, which he said was unexpected.

However, Sklar said, the ruling will likely not have a serious long-term effect from Ontario's ban on sales of Shoppers generic drugs, which have been sold under the Sanis brand.

"With the headline news that Shoppers will not able to sell Sanis in Ontario as a result of the successful appeal, we believe the stock could easily sell off a couple of dollars," Sklar wrote.

"However, we believe that the actual financial impact on Shoppers will be much less severe than some investors might calculate."

Sklar said the Ontario ban won't prevent Shoppers from selling Sanis products in other provinces where they are permitted. In addition, the volume discounts that the retailer gets from its contract drug suppliers will probably offset the revenue it lost when the province banned the fees to it from generic manufacturers..

"As a result, we believe the future negative financial impact of the successful appeal is limited, and any significant downside in the stock could be an opportunity for those investors seeking a position in Shoppers."