Federal officials announced on Tuesday a new policy that will make it possible for undocumented teenage immigrants in federal custody to procure abortions, after nearly three years of litigation regarding the matter.

In a memorandum released on Tuesday, the Administration for Children and Families at the Department of Health and Human Services (HHS) said that staff and providers with the Office of Refugee Resettlement (ORR) would not “obstruct or interfere” with abortions or abortion counseling of “unaccompanied alien children.”

The policy requires that federal staff or contracted care providers ensure that minors seeking abortions “have access to medical appointments related to pregnancy in the same way they would with respect to other medical conditions,” and that they not prevent minors from obtaining abortions, in accord with relevant state laws.

But the policy also provides for opt-outs for religious providers, and clarifies that federal funds cannot be used for legal petitions, if a judicial bypass of state law regarding parental consent is requested.

The new policy was reached as part of an agreement with the ACLU that will end the ACLU’s lawsuits over the issue.

The case dates back to 2017, when the ACLU sued the administration on behalf of an unnamed 17 year-old immigrant who alleged that she had requested an abortion while in a federally-operated shelter in Texas but was not able to procure one because of federal policies.

Since March 2017, ORR policy had barred federally-funded shelters from providing or facilitating abortions without the permission of then-ORR director Scott Lloyd, a Catholic, who said that government shelters should provide pregnancy support to women in custody, but not be compelled to transport minors in custody for abortions.

The immigrant woman, named “Jane Doe” in her complaint, had reportedly received outside funding for the abortion, but HHS declined to transport her to an abortion clinic.

The government argued it had the right to determine what would be in the best interest of minors in federal custody, and also stated that it has an interest in not creating incentives for minors to cross international borders in order to obtain abortions.

At the time, the Texas Conference of Catholic Bishops praised the administration’s policy, and praised the initial appeals court decision that prevented the abortion from occurring.

The Texas bishops said “federal and Texas state officials are to be commended for defending the life of an innocent unborn child in a recent case involving an unaccompanied pregnant minor in federal immigration custody.”

They also said a court’s ruling that year allowing the girl to get an abortion would “require the government to facilitate and participate in ending the innocent life of the unborn child.”

“Indeed, this case, one of many brought by the American Civil Liberties Union (ACLU), has as its objective compelling others to perform, facilitate, or pay for abortion who do not wish to do so. This objective is unconscionable. No one —the government, private individuals or organizations — should be forced to be complicit in abortion,” the bishops urged.

On Oct. 24, 2017, after several rounds of appeals, the D.C. Circuit Court of Appeals ruled that Doe must be helped by the government to get an abortion. She was 16 weeks pregnant, and Texas forbade abortions after 20 weeks. Doe had the abortion the next day, Oct. 25, as the administration did not immediately appeal the decision to the Supreme Court.

Nine days later, after Doe had an abortion, the Justice Department appealed the decision to the Supreme Court, which in June of 2018 vacated the appellate court decision.

But a preliminary injunction—or a halt—to the administration’s policy preventing underage immigrant abortions was still in effect; it was issued in April of 2018.

The new policy announced on Tuesday is similar to that injunction, the ACLU said.

Tuesday’s memo also includes provisions upholding the Hyde Amendment and granting an opt-out for religious health care providers who object to abortion. The Hyde Amendment is federal policy that prohibits federal funding of elective abortions except in cases of rape, incest, or when the life of the mother is at stake.

The memo says that when a teen immigrant is in the care of a religious provider opposed to abortions, ORR staff “will personally deliver any legally required notice” to them.

In the cases where an underage immigrant requests an abortion, but is detained in a state that requires parental notification for minors seeking abortions, the immigrant could obtain a judicial bypass order, the administration says, but ORR staff do not have to fund the immigrant’s legal representation in that case.

If the immigrant gets a bypass order and still wants an abortion, ORR staff cannot prevent them, the memo says.

According to the memo, “the legal position of HHS is that state courts cannot lawfully compel the ORR federal staff or ORR care providers to: consent to the provision of abortions” to underage immigrants.