WASHINGTON — Two hospitals that refused to provide an emergency abortion to a pregnant woman who was experiencing premature labor put her life in jeopardy and violated federal law, a first-of-its-kind investigation by the federal government has found.

The findings, revealed in documents obtained by the Associated Press, are a warning to hospitals as they struggle to reconcile dozens of new state laws that ban or severely restrict abortion with a federal mandate for doctors to provide abortions when a woman’s health is at risk. The competing edicts have been rolled out since the Supreme Court last year overturned the constitutional right to an abortion.

Federal law, which requires doctors to treat patients in emergency situations, trumps the state laws, Health and Human Services Secretary Xavier Becerra said in a statement.

“Fortunately, this patient survived. But she never should have gone through the terrifying ordeal she experienced in the first place,” Becerra said.

The investigation centered on two hospitals — in Joplin, Mo., and Kansas City, Kan. — that in August refused to provide an abortion to a Missouri woman whose water broke at 17 weeks of pregnancy.

Doctors at both hospitals told Mylissa Farmer that her fetus would not survive and that she was at risk of serious infection or losing her uterus, but they would not terminate the pregnancy because a fetal heartbeat was detectable.

Farmer, of Joplin, had to travel to an abortion clinic in Illinois.

“It was dehumanizing. It was terrifying. It was horrible not to get the care to save your life,” Farmer said.

Her complaints launched the first investigations that the Centers for Medicare & Medicaid Services has publicly acknowledged since Roe vs. Wade was overturned last year.