WASHINGTON — A federal appeals court reversed itself Tuesday and ruled that the Trump administration cannot prevent an undocumented teenage girl from getting an abortion.

The full U.S. Court of Appeals for the District of Columbia Circuit ruled 6-3 that the 17-year-old girl, identified as Jane Doe and represented by the American Civil Liberties Union, does not need to secure a sponsor or leave the country in order to end her pregnancy.

All six judges in the majority were named to the court by Democratic presidents, while those dissenting were Republicans' nominees. Similarly, the three-judge panel that sided with the government last Friday was tilted 2-1 in favor of Republicans.

"Today’s decision rights a grave constitutional wrong by the government," Judge Patricia Millett, who had dissented from Friday's decision, wrote. "Remember, we are talking about a child here. A child who is alone 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 that she is pregnant."

The three-judge panel had sought a compromise by giving the Department of Health and Human Services until Oct. 31 to find a sponsor for the girl, who crossed the border into Texas last month and is nearly 16 weeks pregnant. That would facilitate the abortion without involving the government.

Justice Department lawyers had argued in federal district and appeals courts that the girl could return to her home in Central America for an abortion. But the ACLU argued that would deny her the chance to remain in the United States, and that finding a sponsor could take too long.

Millett, one of four judges named to the powerful appeals court by President Barack Obama, based her dissent last week on Supreme Court precedents from 1992 and 2016 that blocked governments from placing an "undue burden" in the way of a chosen abortion.

"The government may not put substantial and unjustified obstacles in the way of a woman’s exercise of her right to an abortion pre-viability," Millett said Tuesday. "The government, however, has identified no constitutiona ally sufficient justification for asserting a veto right over J.D. and Texas law."

Judge Brett Kavanaugh, viewed as near the top of President Trump's short list for the next Supreme Court vacancy, dissented along with two other Republican presidents' nominees. He cited the high court's precedents, under which he said "the government has permissible permissible interests in favoring fetal life, protecting the best interests of a minor, and refraining from facilitating abortion."