SALT LAKE CITY — The Utah Supreme Court has ruled unconstitutional a piece of state law barring gay couples from reaching a workable surrogacy agreement with a woman they wish to carry their child.

In a written opinion released Friday, the state's high court threw out the ban, finding it denied same-sex couples the same benefit that a husband and wife have long had in Utah.

The decision says in part that "same-sex couples must be afforded all of the benefits the state has linked to marriage."

The law at issue allowed judges to OK gestational agreements only if the intended mother cannot bear a child or if the pregnancy would carry health risks. Without a court's approval, the contracts are not enforceable in Utah.

The requirement posed a problem for male couples like the southern Utah pair that successfully challenged the ban.

In their case, a judge in St. George concluded he had no choice but to deny the their petition after a woman and her husband agreed she would carry the child. The would-be parents had a sound argument, the judge found, but the law refers to a mother, meaning a woman, and they both are men.

Both couples appealed the decision to the Utah Supreme Court, where their attorneys argued the law violates the hopeful parents' constitutional rights to due process and equal protection. The justices agreed on the constitutional point but rejected their argument that a mother should be interpreted to mean a parent.

Troy Williams, executive director of Equality Utah, cheered the decision in a statement. He said it "has stricken discriminating language from Utah's code and affirmed that equality is the law of the land."

The Utah Attorney General's Office, typically tasked with defending state laws, agreed with the couple and supported their argument in court papers.

Generally, when there's no dispute, the state's high court finds it doesn't have jurisdiction and dismisses a case, according to the opinion authored by Chief Justice Matthew Durrant. The court chose to rule on this one because the Utah Legislature has long given courts power to preside over parental rights even when there's no disagreement, Durrant wrote.

Justice John Pearce saw it differently and questioned whether a dispute actually is necessary in most cases the court hears. Justice Thomas Lee disputed Pearce's perspective. Both filed separate opinions that concurred with the overall decision.