(Reuters) — New York's top state court has held that towns have the authority to ban gas drilling within their borders, giving a boost to opponents of the drilling method known as fracking.

The Court of Appeals in a 5-2 decision on Monday upheld drilling bans in the Ithaca, N.Y., suburb of Dryden and in Middlefield, near Cooperstown, N.Y., saying the laws were extensions of the towns' zoning authority.

Drilling company Norse Energy USA and an upstate dairy farmer separately sued the towns, claiming the bans violated a law designed to create uniform statewide regulations on the oil and gas industry.

The court disagreed, saying the law was designed to bar only those local ordinances that could impede the state's ability to regulate drilling activities.

"Plainly, the zoning laws in these cases are directed at regulating land use generally and do not attempt to govern the details, procedures or operations of the oil and gas industries," Judge Victoria Graffeo wrote for the court.

The decision affirmed rulings by three lower courts.

The plaintiffs had told the court that upholding the bans would make drilling companies reluctant to invest in the state, since they would be faced with a patchwork of local laws that could change.

Dryden and Middlefield in 2011 were among the first of more than 170 municipalities in New York to ban gas drilling as state officials considered whether to lift a moratorium on fracking, which is still in place.

Fracking involves blasting chemical-laced water and sand deep below ground to release oil and natural gas trapped within rock formations. It has allowed companies to tap a wealth of new natural gas reserves in other states, but critics say the procedure has polluted water and air, and caused seismic activity near wells.

Officials from Dryden and their attorneys praised the decision.

"Today's ruling shows all of America that a committed group of citizens and public officials can stand together against fearful odds and successfully defend their homes, their way of life, and the environment against those who would harm them all in the name of profit," Dryden Deputy Supervisor Jason Leifer said in a statement.

Thomas West and Scott Kurkoski, who represented the plaintiffs in both cases, did not immediately return requests for comment.

In dissent, Judge Eugene Pigott said the towns' bans went beyond their zoning authority because they include detailed language about drilling activities, such as the storage of gas and use of drilling equipment.

The bans "do more than just regulate land use; they regulate oil, gas and solution mining industries under the pretext of zoning," Judge Pigott wrote, joined by Judge Robert Smith.

The cases are Wallach v. Dryden and Cooperstown Holstein Corp. v. Middlefield, New York State Court of Appeals, Nos. 130 and 131.