The six plaintiffs, who include gay couples, argue the legislation allows magistrates and other officials who perform marriages to put their personal beliefs before their sworn constitutional duty.

“And the law spends public money to advance those religious beliefs,” said Luke Largess, a partner at the Charlotte-based law firm Tin Fulton Walker & Owen that filed the challenge. “That is a straightforward violation of the First Amendment.”

The suit was filed in U.S. District Court in Asheville. A spokeswoman for Attorney General Roy Cooper, a Democrat who is running for governor next year, said his office will defend the state even those he personally opposes the legislation.

North Carolina’s Republican-led legislature passed the law earlier this year as social conservatives nationwide pushed for so-called “religious freedom bills” in response to same-sex marriage becoming legal.

State legislators overrode Republican Governor Pat McCrory’s veto of the measure, allowing it to take effect in June, the same month the U.S. Supreme Court legalized gay marriage across the country.

Magistrates who ask to opt out are barred from performing any marriage, gay or heterosexual, for six months.

Critics say the opt-out option discriminates against gay and lesbian couples. In one county, they said, all magistrates recused themselves, forcing public funds to be spent to bring in magistrates from elsewhere to marry local couples during short shifts.

But Senate Leader Phil Berger, a Republican, noted the lawsuit failed to include anyone who was denied the ability to get married under the law.

“This is just the latest attempt by the far left’s political correctness mob to force their beliefs on everyone else by trampling the First Amendment guarantee of religious freedom,” he said.

Utah is the only other state with a similar opt-out law.

In Kentucky, county clerk Kim Davis was jailed for five days in September after refusing to issue marriage licenses to same-sex couples on the grounds that doing so would violate her religious beliefs.

A U.S. district judge ruled Rowan County Clerk Davis had to live up to her responsibilities as the county clerk despite her beliefs and ordered her to grant the licenses.