A Montgomery Circuit Court judge on Thursday overturned the county’s ban on the use of cosmetic pesticides on lawns, dealing a major setback to environmental advocates who argued that chemicals in the products are unsafe.

Judge Terrence McGann said that the law — the first of its kind for a major locality in the region — would conflict with federal and Maryland state regulations that allow the use of the pesticides. The case was just one example of Maryland counties’ “insatiable appetite to tamper with existing state laws,” McGann said.

Counties have also “tried to hijack a portion of the existing field of law” in areas including tobacco, guns and minimum wage, he said.

The law, passed by a divided County Council in 2015, was to take effect in 2018. It bans pesticides that have been approved by the federal government but contain chemicals that some studies say may cause cancer. The law exempts agricultural land, gardens and golf courses, and does not prohibit the sale of lawn pesticides in the county.

A provision of the bill eliminating the use of herbicides and pesticides on certain county properties, which was not part of the lawsuit filed by a group of homeowners and pesticide companies, took effect in July.

Council member George Leventhal (D-At Large), the bill’s chief sponsor and a candidate for county executive in 2018, said he was “very disappointed” by McGann’s ruling, which he said “sets a worrisome precedent for the ability of local governments to protect their residents on vital issues of health and safety.”

The county has 30 days to appeal McGann’s ruling.

Timothy Maloney, an attorney for the plaintiffs, including Scotts Co., a major manufacturer of lawn-care products, called the ruling a “significant victory for consumer safety.”

If the ban had been upheld, he said, it would have set a legal precedent for the 187 jurisdictions in Maryland to have their own regulatory systems for pesticides.

“There would have been total chaos and confusion in the marketplace,” he said.

McGann said the desire to “avoid confusion from diverse requirements” that could endanger public health is the reason that the state legislature adopted pesticide rules that work with federal Environmental Protection Agency regulations. The Montgomery County ordinance, he said, would disrupt the uniformity established by the legislature.

But environmentalists who support the ban say federal regulations are inadequate — especially now that the EPA under President Trump is rolling back some Obama-era regulations.

“Look at the EPA right now: It is a weak institution,” said Julie Taddeo, an environmental activist and leader of Safe Grow Montgomery who was in court for the ruling. “It’s not doing enough to protect our kids.”

She accused McGann — who frequently makes jokes from the bench and on Thursday quipped that pesticide label-reading was a “cure for insomnia” — of not taking activists’ concerns seriously.

Montgomery County Council President Roger Berliner (D), who also is running for county executive, said he has asked the county attorney to advise the council on whether to appeal the decision and on other possible legal options for reducing residents’ exposure to chemicals.

“With federal safeguards in the areas of public health and environmental protection dwindling, I believe that it is more important than ever for county government to work to protect the health and safety of its residents and our environment,” Berliner said in a statement.

Maloney scoffed at an appeal as “a tremendous waste of taxpayer dollars.” Trump’s election, he said, does not change the “well-established findings and protocols on pesticides” that exist across the United States.