The Virginia House voted overwhelmingly Monday for a bill allowing legislators to hire their own lawyers to defend state laws if the attorney general will not, a measure aimed at protecting the state’s ban on gay marriage.

The Republican-dominated House voted 65-32 for the legislation, which would give the General Assembly the right to intervene in lawsuits challenging Virginia laws or the state Constitution if the attorney general opts not to do so.

The attorney general usually defends state laws or the constitution if it is challenged in court. But Attorney General Mark R. Herring (D) announced last month that he would not defend the state’s constitutional ban on same-sex marriage, submitting a motion to side with two gay couples challenging it in federal court.

Herring said he cannot defend the gay marriage ban, adopted eight years ago with the support of 57 percent of voters, because he believes it violates the U.S. Constitution.

The vote fell mostly along party lines, with Democrat Del. Johnny S. Joannou (Portsmouth) joining Republicans to support the bill and Republican Thomas Davis Rust (Fairfax) voting against. There were two abstentions: Robert Dickinson Orrock Sr. (R-Caroline) and Barry D. Knight (R-Virginia Beach).

The bill now moves to the Senate, where Democrats are expected to kill it.