A federal judge in Washington ordered the Trump administration to allow a teen who is in the U.S. illegally and under the custody of the U.S. government to have an abortion.

U.S. District Judge Tanya Chutkan, who was appointed by former President Barack Obama, said Wednesday she was "astounded" to learn that the 17-year-old girl from Mexico, who is being detained in South Texas, was not allowed to obtain the procedure. She ordered the federal government to transport the girl to an abortion facility or to allow a guardian to take her "promptly and without delay" to have a counseling appointment on Thursday and an abortion by Friday or Saturday.

Chutkan wrote that the girl, known in documents as "Jane Doe," would otherwise "suffer irreparable injury in the form of, at a minimum, increased risk to her health, and perhaps the permanent inability to obtain a desired abortion to which she is legally entitled."

Reports have shown that the Trump administration has prevented minors who are in the country illegally from obtaining abortions. "Jane Doe" is represented by the American Civil Liberties Union, which sued over the federal government's actions, calling them unconstitutional, and also asked the judge to implement a preliminary injunction for when other women face similar cases.

The girl is 15 weeks pregnant, and most abortions in Texas are banned after 20 weeks. The teen followed state law by obtaining permission from a state judge in Texas to have an abortion and said she would pay for the procedure or would do so with help from her court-appointed guardian.

Lawyers for the Justice Department told Chutkan that the girl was not allowed to have an abortion unless it was a medical emergency, saying that because she was in the U.S. illegally she was not entitled to the same access to abortion as legal residents.

In court filings, the government said it has "strong and constitutionally legitimate interests in promoting childbirth, in refusing to facilitate abortion, and in not providing incentives for pregnant minors to illegally cross the border to obtain elective abortions while in federal custody." The lawyer representing the federal government also said the teen could leave to obtain an abortion in Mexico but had chosen to stay in U.S. custody.

Government workers reportedly took the girl to a Christian crisis pregnancy center for counseling and told her mother that she wanted to have an abortion, moves that Chutkan said violated her right to privacy.

Even if a guardian takes the girl to have an abortion, the government has to process paperwork in the same way it would have to do for anyone under its custody who needed to leave for a medical procedure.

In a statement, the administration for Children and Families at the U.S. Department of Health and Human Services said the court made a "troubling ruling that exceeds the U.S. Constitution and sets a dangerous precedent by opening our borders to any illegal children seeking taxpayer-supported, elective abortions."

"We are disheartened the ruling rewards ideologically motivated lawsuits filed in multiple courts by the ACLU and abortion advocates," the statement continued. "Though the order overrides the policies and procedures of the Office of Refugee Resettlement designed to protect children and their babies who have illegally crossed the border, we will continue to provide them with excellent health care and protect their well-being in all our facilities. We will consider our next steps to ensure our country does not become an open sanctuary for taxpayer-supported abortions by minors crossing the border illegally."

The anti-abortion group Susan B. Anthony List objected to the ruling.

"Today's ruling is outrageous and sets a dangerous precedent," said SBA List President Marjorie Dannenfelser. "The U.S. Department of Health and Human Services took a simple position that it would protect the life and dignity of the teenage girl and her unborn child while in their care. Shame on this judge for overruling compassionate care and instead mandating that the U.S. government help facilitate an abortion for a teenage girl."

Dannenfelser accused the ACLU of "recklessly exploiting a teenage girl in order to make the United States a sanctuary state for abortion" and urged the Justice Department to appeal the ruling.