MONTGOMERY, Ala. -- A federal judge has struck down Alabama's one-of-a-kind law that enabled judges to put minors seeking abortions through a trial-like proceeding in which the fetus could get a lawyer and prosecutors could object to the pregnant girl's wishes.

Alabama legislators in 2014 changed the state's process for girls who can't or won't get their parents' permission for an abortion to obtain permission from a court instead. The new law empowered the judge to appoint a guardian ad litem "for the interests of the unborn child" and invited the local district attorney to call witnesses and question the girl to determine whether she's mature enough to decide.

U.S. Magistrate Judge Susan Russ Walker sided Friday with the American Civil Liberties Union of Alabama, writing that the law unconstitutionally and impermissibly imposes "an undue burden on a minor in Alabama who seeks an abortion through a judicial bypass," and violates the girl's privacy rights by enabling a prosecutor to call witnesses against her will.

Get Breaking News Delivered to Your Inbox

Both the judge and the ACLU said they were aware of no other state with such a law.

Every state requiring parental consent for abortions involving minors must also have a "judicial bypass" procedure so that girls can get a judge's approval in a way that is effective, confidential, and expeditious, the ACLU said.

The state had argued that the law was intended to allow a "meaningful" inquiry into the minor's maturity and the process was still a "confidential, and expeditious option for a teenager who seeks an abortion without parental consent."

The civil rights organization said it had the opposite effect, by enabling lawyers for the state or the fetus to subpoena the minor's teacher, neighbor, relative or boyfriend to testify she's too immature to choose an abortion, or that continuing the pregnancy would be in her best interest.

It is unclear how many such proceedings have happened since the law was enacted. Walker noted that a district attorney this summer opposed the abortion request of a 12-year-old girl who had been impregnated by a relative.

The girl was 13 weeks pregnant and had just completed fifth grade when she went before a family court judge, according to a court record. The judge approved the abortion on June 27, and the district attorney appealed the same day, arguing that the girl was too immature to make an informed decision. The Alabama Court of Civil Appeals on July 12 ruled in favor of the girl.

In a statement, Andrew Beck, an attorney with the ACLU, said the ruling was a "victory for women, for young people, and for reproductive health in Alabama."

He added, "By undermining their confidentiality, this law put teenagers participating in the judicial bypass process in real danger."

The ACLU filed the lawsuit in federal court in Montgomery on behalf of Reproductive Health Services, a Montgomery abortion clinic. The Alabama ACLU's executive director, Randall Marshall, praised the federal judge's decision, saying the prosecutor in the 12-year-old's case made her situation worse by delaying her ability to obtain an abortion.