he North Carolina state Senate voted on Wednesday to allow government officials to refuse to marry same-sex couples without fear of being fired, adding a new twist to the gay marriage debate in a region where such unions have faced strong opposition.

North Carolina, which began allowing gay marriages last year to comply with a federal court order, had banned same-sex matrimony in a 2012 referendum. It is among 37 states where gay marriage is legal.

The U.S. Supreme Court last month agreed to decide whether states can ban gay marriage in a ruling that will determine whether 13 remaining state bans will be struck down.

In North Carolina, some of the civil officers who perform marriages, known as magistrates, threatened to resign rather than perform unions that ran counter to their religious beliefs.

While the bill does not mention gay marriage explicitly, it allows employees to recuse themselves from performing marriages by citing a “sincerely held religious objection.”

After submitting their objections in writing, magistrates would be barred from performing any marriage for six months or until they removed their objections.

Senate leader Phil Berger, the Republican who sponsored the bill, cited a case in his home county in which a magistrate was forced to resign over his refusal to perform gay marriages.

Berger said the bill will allow the state to comply with the law while preserving religious freedom.

“While the courts have taken steps to provide special rights to some, we must not ignore the constitutionally protected rights of others,” Berger said in a statement after the bill passed.

“This discriminatory bill treats gay and lesbian couples as second-class citizens and distorts the true meaning of religious freedom,” Reverend Jasmine Beach-Ferrara, director of the Campaign for Southern Equality, said in a statement.

The bill, which also applies to the registers of deeds who issue marriage certificates, would require local governments to ensure that eligible couples are not denied the right to marry.

The bill passed the Republican-controlled Senate by a 32-16 vote and heads next to the Republican-controlled state House, where final action on the bill could come as early as Friday.