New York Democratic Rep. candidate Sean Patrick Maloney is working to attach anti-discrimination language to spending bills. (AP Photo/Stuart Ramson, File, Pool)

The House voted  late Wednesday night to approve a measure to bar the government from paying federal contractors that discriminate based on gender identity or sexual orientation.

Members erupted into cheers Wednesday night after the measure, sponsored by Rep. Sean Maloney (D-N.Y.), was approved 223-195.

The Wednesday vote was the second in less than a week on an issue that divides Republicans as a party and is proving equally contentious among GOP lawmakers in the House.

Maloney, who is openly gay, resurrected his language as an amendment to the energy and water spending bill. The overall spending bill is scheduled for a final vote on Thursday.

Maloney celebrated after the vote by tweeting his thanks to the House members who voted for the bill.

But Republicans are pushing back in a broader effort to preserve “religious liberty” from Obama’s recent actions — one to prevent discrimination against LGBT employees of federal contractors and the other directing the nation’s public schools to provide bathrooms and locker rooms for transgender students that correspond to their gender identity.

The House also voted 233-186 to approve a measure introduced by Bradley Byrne (R-Ala.) that would exempt religious groups from Obama’s directives to contractors and public schools.

“We should have no problem ensuring that religious entities still enjoy the protections of the free exercise of religion,” Byrne said on the floor.

“It sounds like discrimination in the disguise of religious freedom,” said Rep. Marcy Kaptur (D-Ohio).

Republicans successfully tweaked the Maloney amendment after Rep. Joe Pitts (R-Pa.) introduced his own language stating that “the administration must not run afoul of the 1st amendment, the 14th amendment and Article One of the Constitution” in its anti-discrimination effort.

Maloney said he had no objection to Pitts’s proposal, but clarified he didn’t think his measure violated those provisions in the first place.

“Far from being concerned about reconciling our activities with the Constitution, we believe they are perfectly consistent,” Maloney said. “What do you say we abide by the whole Constitution, including the parts that try to make it more progressive, more inclusive of people like me, of people of color, of women, of people who were shut out when it was written?”

LGBT rights have sparked an intense political debate around the country and last week, exploded onto the House floor when Maloney tried to include his language about federal contractors in a military construction and veterans’ affairs bill. The episode signaled the start of what is likely to be a long and controversial battle over so-called religious liberty and other LGBT measures in the context of the congressional budget process.

Because the 12 spending bills are among the only must-pass legislation on Congress’s plate, supporters and defenders of such measures are likely to use them as vehicles for such proposals.

Speaker of the House Paul D. Ryan (R-Wisc.) told reporters on Tuesday that the breakdown last week was the result of confusion about the amendment and a fear that the issue could undermine support for the overall bill.

“A lot of folks didn’t know what they were voting on,” Ryan said. “There was a real concern that this was going to jeopardize critical funding for our  Veterans Administration and the military.”

Maloney said Wednesday that the intent of his proposal was clear.

“It said you can’t take taxpayer dollars and fire people just for being gay,” Maloney said on the House floor.

Last week, Maloney’s proposal looked poised to pass, 217 to 206, before GOP leaders seemed to begin a last-minute scramble to rally Republicans against it.

The language ultimately failed, 213 to 212. Democrats said seven GOP members who originally supported it — Reps. Darrell Issa, Jeff Denham, Mimi Walters and David Valadao of California; Greg Walden (Ore.), David Young (Iowa), and Bruce Poliquin (Maine) — wound up in the “no” column.

Several spokesman for those Republicans did not comment on whether they switched their votes. In a statement, Poliquin said he was “outraged that political opponents or members of the press would claim or insinuate that I cast a vote due to pressure or party politics.”

Democrats booed and shouted as the amendment failed, and party leaders unleashed a wave of criticism.

House Democratic Whip Steny Hoyer (D-Md.) spoke out on the episode Tuesday, saying GOP leaders pushed members to oppose Maloney’s amendment after conservatives threatened to tank the overall bill if it contained the language.

“Unless the bill allows for discrimination we’re not going to vote for it?” Hoyer said. “What kind of argument is that?”

As part of their pledge to maintain regular order, McCarthy and Ryan (R-Wisc.) have said they are committed to maintaining an open amendment process, allowing any member to introduce language once a bill hits the House floor.

Ryan has floated the idea of changing the House rules to require members to submit amendments in writing before they are debated on the floor. Those rules aren’t now in place, however.

“This is the second time in less than a week that Speaker Ryan has abandoned regular order in the name of furthering LGBT discrimination in this country,” said House Minority Leader Nancy Pelosi (D-Calif.) in a statement. “Obviously, we are deeply disappointed that the House Republican leadership has apparently decided that discriminating against LGBT Americans is top a legislative priority.”