DES MOINES, IOWA—Abortion-rights groups said Tuesday that they had filed a lawsuit challenging the nation’s most restrictive abortion law, an Iowa provision that bans most abortions once a fetal heartbeat is detected, around the sixth week of pregnancy.

The state’s attorney general said he would not defend the law, which was slated to take effect July 1. Democrat Tom Miller said he based his decision on a belief that the measure “would undermine rights and protections for women.”

Planned Parenthood and the American Civil Liberties Union are seeking an injunction that would put the law on hold during the lawsuit, a process that could take years.

Republicans want any legal challenge to reach the U.S. Supreme Court in hopes of overturning the 1973 Roe v. Wade ruling.

The law is the latest to test the legality of abortion restrictions. GOP lawmakers in Mississippi earlier this year passed a 15-week abortion ban. It was signed into law by Mississippi’s Republican governor and quickly put on hold after a court challenge.

Iowa Gov. Kim Reynolds, who signed Iowa’s ban earlier this month, indicated she expected the measure to face litigation.

The law is evidence of the state’s conservative shift after the 2016 election, when Republicans gained control of the Legislature and the governor’s office for the first time in nearly 20 years. Last year, they approved a 20-week abortion ban and required women to wait three days before they could have an abortion. The waiting provision is on hold because of a separate lawsuit filed by Planned Parenthood and the ACLU.

Iowa Republicans last year also gave up millions in federal dollars to create a state-funded family-planning program that prohibits participation from abortion providers such as Planned Parenthood.