DES MOINES, Iowa -- An Iowa judge agreed Friday to temporarily block the most restrictive abortion law in the country under an agreement between the state and abortion rights groups. Attorneys for the state and Republican Gov. Kim Reynolds told the judge they agreed to prevent the law from taking effect on July 1 after discussions with three groups challenging the law: the American Civil Liberties Union of Iowa, Planned Parenthood Federation of American and the Emma Goldman Clinic.

The groups are suing the state, arguing that the law, which bans most abortions if a fetal heartbeat can be detected, is unconstitutional. An attorney representing the state said Friday that the goal now is to quickly get the case before a judge "for the sake of getting to a resolution on the merits sooner and better."

"This is a much better outcome for women than having to spend the next few weeks worrying about whether or not they're going to be able to exercise their fundamental right to have a safe and legal abortion in Iowa," said Rita Bettis, ACLU of Iowa attorney.

Get Breaking News Delivered to Your Inbox

Judge Michael Huppert said he would formally issue a temporary injunction later Friday. The injunction means the law won't go into effect until the lawsuit is resolved, which could take months. Both sides have said they want the case to go to the Iowa Supreme Court -- though anti-abortion rights groups are aiming for the U.S. Supreme Court.

The state is being represented for free by the Thomas More Society, a conservative Chicago-based law firm that stepped in after Democratic Iowa Attorney General Tom Miller refused to defend the law. Miller said he believed the law undermines the rights and protections for women.

Reynolds signed the law May 2, two days after lawmakers approved the legislation. The moves marked a dramatic change in abortion policy in Iowa, which before the 2016 elections had little to no role in the broad Republican effort to overturn Roe v. Wade. The landmark 1973 U.S. Supreme Court ruling that established a woman's right to terminate a pregnancy until a fetus is viable.

Protesters rally outside Iowa Gov. Kim Reynolds' formal office, Friday, May 4, 2018, at the Statehouse in Des Moines, Iowa. The protest called for Iowa Gov. Kim Reynolds to veto a six-week abortion ban bill that would give the state the strictest abortion restrictions in the nation. Charlie Neibergall/AP

The 2016 election flipped control of the Iowa Senate, putting Republicans in charge of the Legislature and the governor's office for the first time in two decades. Among the results: numerous anti-abortion bills, including a 20-week abortion ban and a requirement that women wait three days before ending a pregnancy.

The waiting provision -- one of the longest in the country -- also is on hold because of a different lawsuit. Iowa Republicans also gave up millions in federal dollars last year to create a state-funded family planning program that prohibits participation from abortion providers, such as Planned Parenthood.

If the fetal heartbeat law is eventually allowed to take effect in Iowa, most abortions would be banned after around the sixth week of pregnancy -- a time when, abortion-rights groups say, many women don't even know they're pregnant.

Planned Parenthood and the Emma Goldman Clinic, which is in Iowa City, said they provided nearly 3,000 abortions last year. They argue the law is an all-out ban on abortion, in violation of women's constitutional rights.

"From our side, there aren't really any questions that at six-week gestation an embryo is not viable, so it is hard to imagine how this (court fight) could take a very long time," Bettis said. "But we will wait and see what their answer says ultimately then we'll have a better idea."

Martin Cannon, a lawyer with Thomas More Society, noted that the latest lawsuit was filed in state court, meaning getting the case into the federal court system is difficult. But, he said, "there is plenty to argue about right here in Iowa in front of this supreme court."

Bob Vander Plaats, CEO of the conservative Christian group Family Leader, said he and other anti-abortion activists aren't deterred.

"This is going to be the long game," he said. "I do believe that this will be the vehicle that will end abortion in this country."