Tom Williams/CQ Roll Call via Getty Images Rep. Sean Patrick Maloney tried to strip out a measure that allowed discrimination against LGBT employees, but the GOP scrambled to keep it in.

WASHINGTON -- An unexpectedly dramatic scene unfolded on the House floor Thursday as lawmakers clashed over stripping language out of a bill that allows for discrimination against lesbian, gay, bisexual and transgender people.

During debate on a military spending bill, Rep. Sean Patrick Maloney (D-N.Y.) offered an amendment to nullify a provision in a separate bill, the National Defense Authorization Act, that the House passed late Wednesday. The provision opens the door to government contractors citing religious liberty as grounds for firing or harassing employees who are LGBT.

Democrats, and some Republicans, unsuccessfully tried to keep the language out of the NDAA bill. So Maloney, who is openly gay, put up his amendment Thursday to try again on a different bill.

As the votes came in, it became clear Maloney had the support to pass his amendment. The clock ran out and the tally was 217-206. Some lawmakers cheered.

C-SPAN The clock hit zero and the votes were there to pass Maloney's amendment. But GOP leaders held the clock open for several more minutes and persuaded just enough Republicans to switch their votes.

But the vote isn't official until the gavel comes down, and the Republican lawmaker in the speaker's chair held the vote open for several more minutes -- a sign that GOP leaders were working on flipping some of their members from yes to no.

That's when the booing began. Lawmakers began chanting, "Shame! Shame! Shame!" and "regular order!" -- meaning the gavel should come down since the clock ran out. In the meantime, the vote tally began to shift. A handful of Republicans slowly changed their votes from yes to no. By the end, the vote was 212-213 and the gavel came down to loud boos.

You can see a breakdown of how each lawmaker voted here.

Minority Whip Steny Hoyer (D-Md.) immediately challenged the vote, but he was denied. He was agitated enough, though, to later name each of the Republican lawmakers who flipped their votes.

Watch the scene unfold in the video below.