SALT LAKE CITY — The Utah Supreme Court has struck down a portion of law that banned same-sex couples from entering into gestational agreements to have children.

In a ruling on Thursday, Chief Justice Matthew Durrant said “same-sex couples must be afforded all of the benefits the State has linked to marriage and freely grants to opposite sex-couples.”

The case involved an unnamed gay couple from southern Utah who entered into a surrogacy agreement with a heterosexual couple. The four filed a joint petition in 5th District Court to validate the agreement. But the judge expressed concern about Utah law that explicitly stated it could only be if the “intended mother is unable to bear a child or is unable to do so without unreasonable risk to her physical or mental health or to the unborn child.”

The judge denied the couples’ petition, arguing that the law’s use of the words “mother and her plainly refer to a woman” and that because neither of the legally married intended parents were women, he had no choice. The couples appealed to the Utah Supreme Court challenging the constitutionality of the law in light of marriage equality being granted nationwide in 2015.

In the case, the Utah Attorney General’s Office did not oppose the couples and, in fact, told the Court that the statute should be interpreted to be gender-neutral. But the legislature was explicit in its use of “mother,” “birth mother,” and “woman,” the Court said.

So the justices, in a unanimous ruling, struck down that part of Utah law.

“A valid gestational agreement is undoubtedly a benefit linked to marriage,” Chief Justice Durrant wrote. “Obtaining a valid gestational agreement is, in many cases, one of the most important benefits afforded to couples who may not be medically capable of having a biological child. Such an agreement works to secure parental rights to an unborn child and bestows rights and benefits on the intended parents. The State has explicitly conditioned this benefit on a petitioner’s marital status; no unmarried couple may obtain one. It is therefore unquestionably linked to marriage.”

The Court preserved the remainder of the law in order to keep gestational agreements valid, regardless of who seeks them.

Edwin Wall, the attorney for the couples, did not immediately respond to a request for comment from FOX 13 on Thursday night.

“This is a positive step to protect children, intended parents and strengthens families,” said Troy Williams, the director of the LGBTQ rights group Equality Utah, in a statement Friday.

But while the Utah Supreme Court was unanimous in its rulings, there was a split between justices over whether they should have even considered a case where the Utah Attorney General’s Office did not explicitly defend the law. It highlighted a disagreement over the power of the Utah Supreme Court to decide issues of constitutionality where there is not necessarily a conflict.

Justice John Pearce and Associate Chief Justice Thomas Lee appeared to disagree over whether the Court could entertain cases where there is no adverse party.

“If it were up to me, moreover, we would not be opining on the wide-ranging, important constitutional questions introduced into this case by Justice Pearce — as they are not squarely presented to us and have not been briefed by the parties,” Justice Lee wrote. “Justice Pearce has raised them, however, in anticipation of the effect our opinions here may have on ‘future cases.'”

Read the Utah Supreme Court ruling here: