The Trump administration will no longer block immigrant teens in federal custody from accessing abortion services, according to an agreement approved Wednesday by a judge in Washington.

The revised policy comes three years after the American Civil Liberties Union went to court on behalf of a pregnant 17-year-old from Central America. The lawsuit accused the government of imposing an unconstitutional abortion ban on hundreds of pregnant girls in federal custody each year.

As part of the new policy, the administration’s Office of Refugee Resettlement clarified that shelters cannot interfere with access to reproductive health care, including abortion.

The controversy landed in court in 2017 and attracted broad attention because of the earlier involvement of Supreme Court Justice Brett M. Kavanaugh, who previously served on the U.S. Court of Appeals for the D.C. Circuit.

The teenager tried to get an abortion while she was held in a government-funded shelter in Texas. A local judge had determined that the teen was mature enough to bypass the state’s parental consent requirement.

But the government office had adopted a policy of refusing to “facilitate” abortions for pregnant teens in custody who crossed the border illegally without their parents. The former director of the office, E. Scott Lloyd, said government-backed shelters should support “only pregnancy services and life-affirming options counseling.”

The position was a departure from the policy of the Obama administration, which did not block migrants in U.S. custody from having abortions at their own expense.

U.S. District Judge Tanya Chutkan issued an injunction in 2018 preventing the administration from standing in the way of minors obtaining an abortion while the lawsuit was pending. After the change in policy this week, the two parties moved to voluntarily dismiss the case, and Chutkan officially approved the action on Wednesday.

“We are relieved that the government finally abandoned its attempts to block young people in its custody from accessing abortion,” Brigitte Amiri, deputy director of the ACLU Reproductive Freedom Project, said in a statement. The policy change, she said, “rights one of the wrongs this administration has committed against immigrants in detention.”

The Justice Department, which defended the policy, did not immediately respond to a request for comment.

As a result of the lawsuit, the teen known in court as Jane Doe was allowed to terminate her pregnancy. The ACLU then learned of other young women in custody who were prevented from accessing abortion services.

According to the revised policy filed in court, federal officials and shelter staff may “not take actions to obstruct or interfere with” access to court proceedings, abortion counseling or an abortion. Care providers and federal officials are also required to ensure access to medical appointments related to pregnancy “in the same way they would with respect to other medical conditions.”

In a statement through the ACLU, Doe said, “I am so glad to know that what happened to me will never happen to anyone else.”

“No one should be shamed for making the right decision for themselves or blocked from doing so.”

The case took on greater significance because of Kavanaugh’s initial involvement at the appeals court in Washington. While his nomination to the Supreme Court was pending, abortion rights advocates pointed to the case as evidence that Kavanaugh would allow more restrictions on abortion than his predecessor Anthony M. Kennedy.

When the case was on appeal, Kavanaugh’s colleagues reversed his order that would have delayed the teen’s access to an abortion. In dissent, Kavanaugh accused the court of creating a “new right for unlawful immigrant minors in U.S. government detention to obtain immediate abortion on demand.”