By Marti Maguire

RALEIGH, N.C. (Reuters) - A measure that would allow some public officials in North Carolina to opt out of performing gay marriages moved closer to becoming law on Monday, when lawmakers voted to override Republican Governor Pat McCrory’s veto of the bill.

The Republican-led state Senate reached the three-fifths majority needed to override McCrory’s veto in a 32-16 vote. The legislation now goes back to the Republican-controlled state House of Representatives, which passed it last week by a margin wide enough to override the veto.

The bill allows magistrates and other officials to refuse to perform marriages or issue marriage certificates by citing a “sincerely held religious objection.” Once they have asked to opt out in writing, magistrates would be barred from performing any marriage, gay or heterosexual, for six months.

Senate leader Phil Berger said the bill struck a balance between the legal ruling that allowed same-sex marriages to begin in the state last year and the rights of state employees to exercise their religion.

“If the federal courts say they will be performed, they will be performed,” Berger said before Monday's vote. “But if someone takes a job, they don’t park their First Amendment rights at the door. They are entitled to exercise those rights.”

Democrats said the measure would likely delay marriages for gay couples, making the state vulnerable to lawsuits claiming unfair treatment.

“We want to be on the right side of history, not creating loopholes for unlawful discrimination," Democratic Senator Floyd McKissick said.

Announcing his veto last week, McCrory said public officials who swore to defend the Constitution and perform their duties of office should not be exempt from upholding their oath.

Similar bills were filed in several states this year, although none has become law yet, the American Civil Liberties Union said.

Gay marriage is legal in 37 states and Washington, D.C. The U.S. Supreme Court is expected to decide by the end of June whether same-sex marriage should be legal nationwide.

(Story corrects timing of House vote in second paragraph: "last week" instead of "in February")

(Editing by Colleen Jenkins and Mohammad Zargham)