Editor's note: This story has been updated to reflect that the Texas Senate gave Senate Bill 522 its final approval.

The Texas Senate on Tuesday gave initial approval to a measure allowing county clerks to recuse themselves from signing marriage licenses for same-sex couples because of religious objections.

On a 21-10 vote, senators approved Senate Bill 522 by Brian Birdwell, R-Granbury, under which a county commissioners court would appoint another official to issue a marriage license to same-sex couples if the clerk objects because of religious beliefs. The measure would also allow judges to refuse to perform marriage ceremonies for same-sex couples.

State Sen. Eddie Lucio Jr. of Brownsville was the only Democrat to join Republicans in voting for the measure, which must still obtain final approval before it’s sent over to the House. (Update, April 12: The Texas Senate did give the measure its final approval on Wednesday.)

The legislation comes almost two years after the U.S. Supreme Court’s ruling legalizing same-sex marriage, after which some same-sex couples in Texas ran into obstacles in obtaining marriage licenses because of county clerks' religious opposition to their marriages.

On Tuesday, Birdwell said the measure enables government officials to “follow the law without being forced to compromise their religious liberty” by formalizing the recusal process available to county clerks.

It “guarantees county clerks and every American the free exercise of religion even when they are working for the government,” Birdwell told his colleagues on Tuesday.

In questioning Birdwell, Democratic senators were quick to assert that legislation would allow government employees to discriminate against same-sex couples by refusing to perform their legal duties, and they questioned the need for the law when county clerks and judges can already recuse themselves if they appoint a deputy or another employee to take over their responsibilities.

“I have very strong, deeply held religious beliefs on a number of issues, and I’ve been a judge and I have faced some difficult decisions to make,” said state Sen. Sylvia Garcia, D-Houston. “But I’ve also known that if I just couldn’t handle a case ... then I would recuse myself.”

Birdwell responded that his legislation seeks to formalize that process for county clerks and write those protections into law for judges.

The legal quagmire surrounding government officials’ ability to opt out of issuing same-sex marriage licenses or performing same-sex wedding ceremonies came to light following the Supreme Court’s 2015 ruling saying same-sex couples have a constitutional right to marry.

Shortly after that decision came down, Texas Attorney General Ken Paxton issued an opinion saying federal and state religious freedom laws protect county clerks and judges who do not perform their duties when it comes to same-sex couples if those marriages violate their religious beliefs. But his opinion came with a warning that they could be sued.

As conservative attorneys geared up to defend such government employees, they indicated that existing laws ensured their religious freedom. Because there are no blanket protections for county clerks and other government employees who reject same-sex marriage in their official capacity, those cases are considered on an individual basis.

But government officials could also be offered “reasonable accommodations” by delegating their responsibilities to other employees who have no objections.

Civil rights attorneys have agreed that there is room for religious accommodations for government officials as long as those accommodations don’t place an undue burden on same-sex couples or cause a delay in obtaining a marriage license, which was the case in Hood County, where a gay couple was at first unable to obtain a marriage license.

Echoing those concerns, Garcia on Tuesday offered up an amendment to add language to the legislation saying no couple can be burdened by a county clerk’s refusal to certify their marriage license. Birdwell accepted that amendment before the Senate signed off on the legislation.

Read related coverage: