WASHINGTON — Democrats shouted “Shame! Shame!,” but seven Republicans switched their votes under pressure from House leaders Thursday and defeated a measure to protect gay rights.

“They literally snatched discrimination from the jaws of equality,” Rep. Sean Patrick Maloney said. The final vote was 213-212 after the chaos on the House floor. That was enough to defeat an amendment by Rep. Sean Patrick Maloney, D-N.Y., aimed at upholding an executive order that bars discrimination against LGBT employees by federal contractors.

Maloney and other Democrats were incensed. “They literally snatched discrimination from the jaws of equality,” Maloney said.

He said he had approached Majority Leader Kevin McCarthy, R-Calif., as McCarthy worked on GOP colleagues to vote against the measure. McCarthy told Maloney to get back on his side of the aisle.

“I told him, ‘What side am I supposed to stand on in support of equality?'” said Maloney, New York’s first openly gay congressman. “It was disgraceful.”

McCarthy rejected the assertion that Republicans unfairly held the vote open to prevail. “Was that a long time? So the answer is no,” he said.

Maloney’s amendment would have prohibited the use of taxpayer dollars to violate President Barack Obama’s executive order barring discrimination.

He was trying to include it in a spending bill following passage late Wednesday of a defense policy bill that included a provision Democrats said would overturn the executive order. Republicans said the measure was simply a restatement of religious liberties from the 1964 Civil Rights Act, and they bristled at Democratic criticism.

“There are some people who are emotional … that’s beyond the pale. They can say whatever they want to but that’s beyond the pale,” said Rep. Bill Flores, R-Texas, asked about Democrats saying Republicans were a party of hate. “This country has a First Amendment that protects religious liberties, and that’s all we were doing is protecting that.”

House Speaker Paul Ryan, at a news conference immediately after the vote, denied knowledge about the vote-switching.

“This is federalism. The states should do this. The federal government shouldn’t stick its nose in this business,” said Ryan, R-Wis. GOP aides said adding the amendment would have jeopardized passage of the underlying spending bill for military construction and veterans, imperiling the House appropriations process just as it’s beginning.

The vote for Maloney’s amendment peaked at 217, beyond the majority needed for passage, before it began a sporadic decline. Members of the Republican leadership whose job is to round up needed votes were stalking the House aisles where GOP lawmakers seat, and they openly pleaded for support.

“Need two more votes,” Rep. Steve Russell, R-Okla., said loudly as he prowled among Republicans.

Democrats were outraged, loudly chanting as their leader, Rep. Nancy Pelosi of California, yelled up from near the well of the House at her members, shouting at them to vote down the underlying bill.

In the end, 29 Republicans joined 183 Democrats backing the gay rights amendment, but it was not enough.

Democrats were quick to publicize the name of the Republican vote-switchers: Reps. Darrell Issa, Jeff Denham, David Valadao and Mimi Walters of California; Greg Walden of Oregon; Bruce Poliquin of Maine; and David Young of Iowa.

___

Associated Press writers Alan Fram and Mary Clare Jalonick contributed to this report.