RALEIGH (AP) — Duke Energy has agreed to remove millions of tons of coal ash containing toxic heavy metals from a power plant in North Carolina.

The nation’s largest electricity company announced Wednesday that it would dig up three huge pits of water-logged ash at the Buck Steam Station near Salisbury. The ash will be dried and either offered for use in making concrete or moved to lined landfills elsewhere.

Duke agreed to remove the dumps to settle a federal lawsuit filed two years ago by the Southern Environmental Law Center. The ash — left behind when coal is burned to generate electricity — contains such toxic chemicals as lead and mercury, which over time can seep into the groundwater.

Duke’s handling of coal ash and the company’s sometimes cozy relationship with state regulators has been under scrutiny since a dump at a different Duke plant ruptured in 2014, coating miles of the Dan River in gray sludge.

The Associated Press soon reported that concerning levels of chemicals contained in coal ash were found in drinking-water wells in Dukeville, a rural hamlet adjacent to the Buck plant. Among them, hexavalent chromium is known to cause lung cancer when inhaled, and the U.S. Environmental Protection Agency says it is likely to be carcinogenic when ingested.

Duke denies its dumps contaminated the wells but has been providing bottled water to the residents.