A federal judge struck down a controversial law in North Carolina on Tuesday that banned abortions after the 20th week of pregnancy.

U.S. District Judge William Osteen declared the ban unconstitutional in response to a 2016 lawsuit filed by several abortion rights organizations. Osteen cited other successful lawsuits around the country that have taken down bans on abortions that were based on weeks of pregnancy or gestational events. His decision will allow women in the state to obtain an abortion at any time prior to the viability of a fetus, which Osteen said would need to be determined on a case-by-case basis rather than by an arbitrary timeline.

“The Supreme Court has recognized that, while viability is the point at which the state’s legitimate interest rises to a level that may support an outright ban (with appropriate health exceptions), viability does not occur at a fixed number of weeks after the pregnancy begins but rather is determined individually in each case by a doctor,” the judge wrote in a 48-page decision. “No matter what the state’s legitimate interest in restricting abortion, this interest can never support an outright ban prior to viability.”

The Charlotte Observer notes that North Carolina has had several incarnations of abortion laws on the books for decades. The legislation that Osteen struck down on Tuesday centered on an amendment of a 1973 law that tightened the definition of a medical emergency for pregnant women.

Osteen, who was appointed by President George W. Bush, gave the North Carolina General Assembly 60 days before his ruling goes into effect, allowing lawmakers two months to write a new law or file an appeal.

“This court declines to act in a manner that would deprive the North Carolina legislature the opportunity, in the first instance, to either pass legislation or challenge this decision on appeal, whichever they decide may be in the interests of the citizens they represent,” the judge wrote.

The move was immediately hailed by abortion-rights advocates, including the plaintiffs in the suit, Planned Parenthood, the American Civil Liberties Union and the Center for Reproductive Rights.