A federal judge on Wednesday ordered the U.S. government to allow an undocumented teenager in their custody to have an abortion, after saying she was “astounded” the Trump administration was trying to prevent the procedure.

Lawyers for Attorney General Jeff Sessions signaled to U.S. District Judge Tanya Chutkan in Washington that the 17-year-old, who crossed the border from Mexico illegally last month, did not have a constitutional right to an elective abortion in federal custody, unless it was a medical emergency.

Chutkan, an Obama administration nominee, said the government appeared to be presenting the teenager identified in court papers as “Jane Doe” with two options: Voluntarily return to a nation she fled to procure an abortion, or carry an unwanted pregnancy to term.

“I am astounded by that position,” Chutkan said in a 40-minute hearing that was mostly consumed by a back-and-forth between the judge and Scott Stewart, a deputy assistant attorney general.

She ordered the government to transport the teenager to have the procedure — or allow her guardian to transport her — “promptly and without delay.”

Lawyers for the American Civil Liberties Union, which is representing the girl, asked Chutkan for an emergency restraining order to prevent the government from blocking the girl’s plan to have an abortion. They also sought a preliminary injunction to protect others seeking abortions.

ACLU lawyer Brigitte Amiri argued that it was “out of any sort of constitutional bounds” for the U.S. government to block the teenager’s legal right to an abortion, which is preserved in the 1973 Supreme Court Roe v. Wade ruling. A federal magistrate judge in California agreed with the ACLU earlier this month but said she could not rule in the case because the girl is detained in South Texas.

But Stewart told the judge that pregnant undocumented minors from other countries are not entitled to abortions, and said in court records that opening the door to that right “would significantly infringe on the government’s interests in preserving life and protecting national boundaries.”

“I respectfully disagree that she’s entitled to an abortion” facilitated by the government, he said, noting that the girl’s case was not a medical emergency. 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.”

Chutkan countered that the teenager does not need a medical emergency to exercise her right to an abortion. She said the girl had followed state and federal rules: She obtained permission from a state judge in Texas to have an abortion and would cover the expenses herself or with help through her court-appointed guardian.

All the government had to do, the judge said, is process the paperwork to let the girl visit the clinic, just as they would if she needed to have her tonsils removed.

Stewart said the girl could also voluntarily leave the United States and find another way to have an abortion, and said the girl had chosen to remain in federal custody instead of returning home.

That claim appeared to irk the judge, who pointed out that the federal workers took the girl, against her wishes, to a Christian pregnancy facility for counseling and also informed her mother about the abortion. Both steps potentially violated the girl’s constitutional right to privacy and other protections, Chutkan said.

“The government certainly had no problem taking her against her will to receive pregnancy counseling, which was designed to change her mind,” Chutkan said. “The government didn’t seem to have any problem facilitating that.”

The judge and Stewart also sparred over whether some aspects of the law remain undisputed.

Chutkan asked Stewart if he thought illegal immigrants had constitutional rights and if he believed that Roe v. Wade, which guarantees a woman’s right to an abortion, is still the “law of the land.”

Stewart acknowledged the Supreme Court’s ruling but said the government views this case differently because the teenager is an undocumented immigrant in federal custody.

He also said undocumented immigrants have “minimal” protections in this country.

“I’m not going to give you a concession on that your honor,” he said.

The judge laughed. “This is remarkable,” she said.

During the hearing, Chutkan also answered her own questions, saying the girl’s legal status was “irrelevant” and that “despite the fact that she’s in this country illegally, she still has constitutional rights.”

However, the girl is quickly running out of time to have a legal abortion in the United States. The girl is 15 weeks pregnant, and Texas bars most abortions after 20 weeks.

The girl’s native country was not identified during the hearing, and it is not clear that abortion is legal in her homeland if she were to return home. She was apprehended in the United States in September after crossing the U.S.-Mexico border.