RICHMOND — By the narrowest of margins, the state Senate on Monday killed a House bill that would have required Virginia’s attorney general to defend any state law whose constitutionality is challenged.

Proposed by Del. Brenda L. Pogge (R-James City), the measured appeared to be aimed at Attorney General Mark R. Herring (D), who last year declared the state’s ban on same-sex marriage unconstitutional and joined two same-sex couples in asking a federal court to strike it down. Months later, the Supreme Court allowed same-sex marriages to take place in Virginia when it refused to take up a lower court ruling that overturned the ban.

Herring’s move had thrilled gay-rights activists but infuriated conservatives who asserted that the attorney general had a duty to defend state law. Herring said at the time that he had concluded that the ban was in conflict with the U.S. constitution, which he also has a duty to uphold.

“The federal constitution trumps the state constitution,” Sen. John Edwards (D-Roanoke) said before the vote. “The attorney general of Virginia did the right thing. He did the courageous thing.”

The Senate voted 20-20 on the bill, with Sen. John Watkins (R-Powhatan) siding with Democrats who opposed it. Lt. Gov. Ralph Northam (D), who presides over the Senate, broke the tie by voting against the bill.

Lt. Gov. Ralph Northam, right, confers with Senate Majority Leader Thomas K. Norment, Jr., (R-James City), left, during the floor session of the Virginia Senate inside the State Capitol in Richmond, Va., Wednesday, Feb. 11, 2015. (Bob Brown/AP/Richmond Times-Dispatch)