A federal appeals court on Thursday ruled that the Environmental Protection Agency must ban a widely used pesticide linked to neurological damage in children from being sprayed on food crops, unless the agency can demonstrate safe uses for the chemical.

The 2-to-1 ruling by judges on the U.S. Court of Appeals for the 9th Circuit comes nearly two years after the Trump administration’s decision to keep chlorpyrifos on the market despite appeals by environmental and public health groups.

The pesticide has been used for a half-century on an array of fruits and vegetables. Over time, though, evidence has associated exposure with health issues such as headaches and blurred vision and longer-term risks such as lower birth weight and neurological damage to children, and pressure has grown for a complete ban.

Thursday’s court decision gives the federal government 60 days to revoke all food-related uses of chlorpyrifos or to detail evidence that it is safe in certain circumstances. “The EPA must act based upon the evidence and must immediately revoke or modify chlorpyrifos tolerances,” the opinion noted.

The judges in the majority also expressed frustration that the agency had gone 14 years — since a 2007 petition to pull the pesticide from the market — without putting the issue to rest: “During that time, the EPA’s egregious delay exposed a generation of American children to unsafe levels of chlorpyrifos.”

Environmental groups that have long pushed for a ban expressed relief at the outcome. “The court ruled in favor of science, which has clearly shown that chlorpyrifos is too dangerous to be used to grow our food,” Jennifer Sass, a senior scientist at the Natural Resources Defense Council, said in a statement.

An EPA statement said officials were reviewing the ruling. “EPA is committed to ensuring the safety of pesticides and other chemicals,” it noted. “The agency is committed to helping support and protect farmworkers and their families while ensuring pesticides are used safely among the nation’s agriculture.”

The Trump administration chose not to further restrict chlorpyrifos in mid-2019, saying that “critical questions remained regarding the significance of the data” around whether the pesticide causes neurological damage in young children.

Then early last year, the primary manufacturer of chlorpyrifos announced plans to halt its production, a decision it said was driven by financial considerations rather than safety concerns. Corteva Agriscience’s announcement came the same day that California made it illegal to sell chlorpyrifos — one of a number of states, including Hawaii and New York, that have moved to block the pesticide from the market.

As evidence has grown about the chemical’s potential health risks, the government has scaled back its use.

Beginning in 2000, companies making chlorpyrifos entered into an agreement with the EPA to phase out its residential use with a few exceptions, such as in ant and roach baits sold in child-resistant packaging. Two years later, the agency made additional label changes aimed at protecting farmworkers, as well as fish, other wildlife and water sources near where chlorpyrifos was sprayed.

But all that stopped short of fully banning chlorpyrifos in agriculture — an outcome that advocates argued was overdue.

In 2015, the Obama administration moved to revoke all uses of chlorpyrifos after EPA scientists determined that existing evidence did not meet the agency’s threshold of a “reasonable certainty of no harm,” given exposure levels in Americans’ food supply and drinking water. EPA staffers cited studies of families exposed to it in apartment buildings and agricultural communities that found lower birth weight and reduced IQ, among other effects.

Before the ban was finalized, Donald Trump became president and reversed course. In March 2017, EPA Administrator Scott Pruitt rejected the agency’s own analysis, saying the agency would reassess the science underpinning that decision — the Obama administration had based its action on epidemiological studies — and make a final determination later.

That action, welcomed by the pesticide industry and Agriculture Department officials who had questioned the EPA’s findings, led to a prolonged court fight.