North Carolina Gov. Pat McCrory, at his election night headquarters in Charlotte, N.C., Tuesday, Nov. 6, 2012. (AP Photo/Chuck Burton)

The North Carolina legislature on Wednesday overrode a veto by Gov. Pat McCrory to enact a new law that will allow court officials to be excused from performing weddings if they oppose same-sex marriage on religious grounds.

McCrory, a Republican, had rejected the measure last week, arguing that government officials should not be permitted to opt out of their sworn duties. But the House and Senate mustered up enough votes to override McCrory’s veto, ushering the bill into law.

The law gives magistrates and other court officials the right to exempt themselves from performing marriages or issuing licenses to same-sex and opposite sex couples for a period of at least six months if doing so would conflict with their “sincerely held” religious beliefs.

“Religious freedom is a fundamental right guaranteed under our state and federal constitutions – and one that our state’s public servants shouldn’t have to leave at the door,” Senate Leader Phil Berger (R-Rockingham), sponsor of the legislation, said in a statement.

But gay rights groups swiftly condemned the measure, which they called mean-spirited and intended to target gays. “We’re a nation of laws, and today the North Carolina legislature is sending a message that discrimination against LGBT people can trump those laws,” Matt McTighe, campaign manager for Freedom for All Americans, a gay rights group, said in a statement.

Same-sex marriage became legal in North Carolina last year after a federal judge threw out the state’s ban on gay unions. The bill is one of several seeking to shield people of faith from participating in same-sex unions and other activities that conflict with their deeply held beliefs; in Michigan, on Thursday, Gov. Rick Snyder (R) signed legislation to allow faith-based adoption agencies to decline placements that violate their beliefs.

The legislative activity is intensifying as the Supreme Court is preparing to hand down what could be a historic ruling on same-sex marriage. The court is expected by the end of the month to decide whether same-sex couples have a constitutional right to marry nationwide or if legalizing the unions should be up to individual states.