WASHINGTON – Democrats shouted “Shame! Shame!” but seven Republicans, including Rep. Bruce Poliquin of Maine, switched their votes under pressure from House leaders Thursday and defeated a measure to protect gay rights.

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 religious organizations that contract with the federal government.

The vote Thursday is just one chapter in a fight that promises to occupy Congress in the coming weeks as both Republicans and Democrats plan further legislative measures to force the House to take a stand on the divide over whether certain policies, such as those concerning hiring practices and public bathrooms, amount to LGBT discrimination or protections for freedom of religion.

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

Maloney said he had approached Majority Leader Kevin McCarthy, R-Calif., as McCarthy worked on Republican 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 after the time allotted to take it had expired so party members who initially had voted in favor of the measure could switch their votes. “Was that a long time? So the answer is no,” he said.

Poliquin emailed a statement to the Press Herald denying he had succumbed to party pressure.

“I am outraged that political opponents or members of the press would claim or insinuate that I cast a vote due to pressure or party politics,” the statement said. “No one controls my vote. I work hard only for the people of Maine’s 2nd Congressional District.

“I abhor discrimination in any form and at any place.”

Maine Democrats and LGBT organizations pounded on Poliquin for his vote.

“Maine’s voter-approved non-discrimination law has been working for more than a decade,” Matt Moonen, executive director of EqualityMaine, said in a statement. “It’s disappointing that Bruce Poliquin chose to follow the orders of Republican leadership by voting to allow discrimination against LGBT people, rather than representing the will of the Mainers he is supposed to be serving.”

Poliquin’s opponent in the November election, Democrat Emily Cain of Orono, called the episode “politics at its absolute worst.” The chairman of the Maine Democratic Party, Phil Bartlett, said: “This betrayal of the LGBT community is just the latest proof that Bruce Poliquin’s loyalty will always lie with Washington Republicans, rather than with his constituents in Maine.”

Maloney’s amendment would have prohibited the use of taxpayer dollars to violate President 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 by Rep. Steve Russell, R-Okla., that would exempt religious organizations that contract with the federal government from certain parts of civil rights law and the Americans with Disabilities Act. Democrats said the measure would overturn Obama’s executive order. Republicans said it 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 of 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.

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

“Need two more votes,” Russell 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, imploring them to vote down the underlying bill.

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

Democrats were quick to publicize the names of the Republicans who switched their votes: Reps. Darrell Issa, Jeff Denham, David Valadao and Mimi Walters of California; Greg Walden of Oregon; Poliquin of Maine; and David Young of Iowa.

Staff Writer Kevin Miller and The Washington Post contributed to this report.