WASHINGTON — A federal appeals court in Washington ruled Tuesday that a 17-year-old who came to the U.S. illegally and has been held in detention must be allowed to get an abortion.

The ruling is a defeat for the Trump administration, which sought to block the abortion unless the teenager could find a sponsor willing to act as a foster parent and remove her from detention. The case has been watched closely by both sides of the abortion debate, because the ruling could affect hundreds of underage women in federal immigration custody.

"We are talking about a child here," said Judge Patricia Millett in a statement concurring with the court's brief unsigned ruling. "A child in a foreign land. A child who, after her arrival here in a search for safety, and after the government took her into custody, learned she is pregnant."

Judge Patricia Millett. U.S. Court of Appeals District of Columbia Circuit / AP

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The Justice Department had argued that even though the woman, known in court papers only as Jane Doe or J.D., had a constitutional right to obtain an abortion, the government could not be compelled to help her get it by releasing her from detention and accompanying her to the clinic to make sure she returned.

But in her concurrence Tuesday, Millett rejected that argument. "Surely the mere act of entry into the United States without documentation does not mean that an immigrant's body is no longer her own. Nor can the sanction for unlawful entry be forcing a child to have a baby."

Related: Court Blocks Immediate Abortion for Undocumented Teen

Three of the 10 appeals court judges dissented. "Despite her physical presence in the United States, J.D. has never entered the United States as a matter of law and cannot avail herself of the constitutional rights afforded those legally within our borders," said Judge Karen Henderson.

The ruling vacated an order issued late last week by a panel of three federal judges. It gave the woman several more days to try to find a sponsor.

The Justice Department could appeal Tuesday's ruling to the U.S. Supreme Court. Spokesman Devin O'Malley said the government was studying it. But the teenager's lawyers called it an important victory.

"Every step of the way, the Trump administration has shown their true colors in this case. It's clear that their anti-woman, anti-abortion, anti-immigration agenda is unchecked by basic decency or even the bounds of the law," said Brigitte Amiri of the ACLU. "No one should have to go to court to get a safe, legal abortion."

According to court records, Jane Doe crossed the southern border on her own in September, unaccompanied by relatives, and was taken into federal custody at a detention center in Texas. After a medical examination revealed that she was pregnant, she sought an abortion. Texas authorities gave her permission, but the Department of Health and Human Services, which runs the detention facility, refused.

Under the Obama administration, young women in Jane Doe's position were allowed to get abortions. But in March, the Department of Health and Human Services announced that all federally funded shelters are prohibited from taking "any action that facilitates" access to abortion by unaccompanied minors.