WASHINGTON — North Carolina’s top public health official acted unethically and possibly illegally by telling residents living near Duke Energy coal ash pits that their well water is safe to drink when it’s contaminated with a chemical known to cause cancer, a state toxicologist said in sworn testimony.

The Associated Press obtained a full copy of the 220-page deposition given last month by toxicologist Ken Rudo as part of a lawsuit. The nation’s largest electricity company has asked a federal judge to seal the record, claiming its public disclosure would potentially prejudice jurors.

Rudo’s boss, state public health director Dr. Randall Williams, in March reversed earlier warnings that had told the affected residents not to drink their water. The water is contaminated with cancer-causing hexavalent chromium at levels many times higher than Rudo had determined is safe.

“The state health director’s job is to protect public health,” testified Rudo, who has been the state’s toxicologist for nearly 30 years. “And in this specific instance, the opposite occurred. He knowingly told people that their water was safe when we knew it wasn’t.”

Chromium is a metallic element that occurs naturally in the environment but can also be produced by industrial activity. Its most toxic form — hexavalent chromium or chromium-6 — is known to cause lung cancer when inhaled, and the U.S. Environmental Protection Agency says it is likely to be carcinogenic when ingested.

As part of his deposition, Rudo said hexavalent chromium would cause an increased lifetime risk of causing tumors in those who drink it, especially for pregnant women, infants and children under age of 12.

In April 2015, North Carolina officials issued letters to the owners of 330 water wells near Duke Energy’s coal-burning plants that their well water was too contaminated with the heavy metals vanadium and hexavalent chromium to use. Some wells showed hexavalent chromium levels many times higher than the state’s warning level — a one-in-a-million risk for a person to develop cancer over their lifetime, according to state officials.

Hexavalent chromium is known to be present in coal ash, the byproduct generated after coal is burned to generate electricity. Duke has said that both forms of chromium can occur naturally in soil, and denies its massive dumps containing coal ash near the affected wells is the source of the contamination.

Williams, an obstetrician and gynecologist who had worked in private practice, was appointed as state health director in July 2015, after the warning letters were issued.

According to Rudo’s deposition, his new boss questioned whether the one-in-a-million risk standard laid out in state law was too strict when applied to the well water near Duke’s coal ash pits. In countermanding the earlier decision, Williams adopted Duke’s previously stated view that the .07-parts-per- billion health standard developed by Rudo and his colleagues based on reviews of the latest scientific studies was too cautious.

Rudo holds a doctorate in environmental toxicology, the study of the harmful effects of various chemicals on the human body. Williams signed the letters reversing the decision himself, after another public health official in Rudo’s department refused on ethical grounds, according to the deposition.

Duke Energy argued in court papers earlier this month that Rudo’s deposition should be kept private because the company’s lawyers had limited opportunities to question him during the July 11 deposition.