The environmental group that sued Newark over elevated lead levels in its tap water more than two years ago has reached a settlement with local and state officials, capping a years-long fight that catapulted the water crisis in New Jersey’s largest city into the national spotlight.

The settlement means a federal judge will oversee Newark’s promises to fix its water problems for the next six months. That includes the city’s ambitious plan to replace the 18,000 underground water pipes responsible for leaching lead into residents’ drinking water.

“It’s a big victory for another generation or many generations of children who are going to have a much healthier and better life because they are not going to be drinking lead in their water every day,” said Erik Olson, senior strategic director for health for the Natural Resources Defense Council, which sued the city and New Jersey’s Department of Environmental Protection.

Newark will also continue offering free water testing for residents and provide a one-year supply of water filters to homes after their lead service lines—the garden hose-sized pipes that pump water from underground water mains into homes—are replaced at no cost by the city. Mayor Ras Baraka said more than 17,000 lead service lines had been switched with copper pipes since the program began in March 2019.

“By the grace of God, we are near completion of our lead service line replacement program, and I am thankful that we were able to identify the issue, do the work, and are able to help make our residents safer,” Baraka said in a statement Tuesday.

The Natural Resources Defense Council together with NEW Caucus, a local coalition of educators, sued Newark in June 2018, alleging the city broke federal rules in the Safe Drinking Water Act and failed to keep residents safe from high levels of lead. Newark officials, meanwhile, insisted for months that the water remained “absolutely safe to drink,” despite having evidence that the city’s water treatment was failing to keep lead out of people’s homes.

The groups pressured Newark to aggressively combat its lead problems, and the city agreed to distribute water filters in October 2018. Newark also temporarily distributed bottled water to 14,000 residents in the summer of 2019 under pressure from the U.S. Environmental Protection Agency.

Lead levels are not allowed to exceed specific federal standards, though no amount of lead in water is considered safe by scientists. Lead can get into drinking water when it dissolves off from outdated plumbing like old faucets or lead solder. If a city doesn’t properly treat its water, it can be too corrosive and more likely to cause the metallic toxin from aging service lines or other plumbing to leach into the water.

Newark’s lead levels at one point were three times the federal limit because the city’s water treatment plant wasn’t using the right mix of chemicals to ensure the water flowing through old pipes didn’t corrode lead plumbing. Newark is now using a new chemical treatment.

Under the agreement, neither the city nor the state admits to breaking federal law. A judge approved the agreement on Tuesday.