By ANDREW TAYLOR, Associated Press

WASHINGTON (AP) — The House reversed itself late Wednesday and approved a measure aimed at upholding an executive order that bars discrimination against LGBT employees by federal contractors.

More than 40 Republicans helped Democrats power the gay rights measure over the opposition of GOP conservatives who dominate the chamber.

Conservatives did prevail in a separate vote designed to make sure federal funding isn't taken away from the state of North Carolina over its controversial bathroom law for transgender people.

Wednesday night's 223-195 tally reverses a vote last week on the gay rights measure. Then, GOP leaders twisted arms to defeat the legislation, causing several supporters to switch their vote, leading Democrats to erupt in protest.

Openly gay New York Democrat Sean Patrick Maloney returned to attach the measure to a funding bill for the Energy Department.

This time, GOP leaders let members vote as they wished; about a dozen Republicans, including several from California, rethought their opposition and Maloney's amendment made it through fairly easily.

It would prohibit agencies funded by the bill to award taxpayer dollars to federal contractors that violate President Barack Obama's executive order barring discrimination against lesbian, gay, bisexual and transgender people.

"It says you do not take taxpayer dollars and fire people just for being gay," Maloney said.

Maloney said last week's vote "snatched discrimination from the jaws of equality."

Earlier, the House voted 227-192 to block several federal agencies from retaliating against North Carolina over its law requiring transgender people to use the bathroom of their original sex.

That amendment, by Robert Pittenger, R-N.C., came in response to warnings from the Obama administration that it may take federal funding away from North Carolina in response to the state law that blocks certain protections for gay people.

"The President and his emissaries have stated ... that funds should not be dispensed to North Carolina until North Carolina is coerced into complying with the legal beliefs of the President, and his political views," Pittenger said. "This is an egregious abuse of executive power."

The North Carolina law was passed after Charlotte passed an ordinance allowing transgender people to use restrooms of their chosen gender identity. The state law went further to take away federal protections for gays, putting the state at risk of losing a variety of federal funds.

Top House Democrat Nancy Pelosi of California blasted Republicans as favoring discrimination against gays.

"Republicans overwhelmingly voted to support ... the hateful and discriminatory state law in North Carolina, and to enable anti-LGBT bigotry across our country," Pelosi said in a statement. "History will not look kindly on the votes Republicans proudly took to target Americans because of whom they are or whom they love."

Maloney's proposal had appeared on track to pass last week, peaking at 217-206 as an amendment to a veterans' spending bill.

But GOP leaders prevailed on seven Republicans to switch their votes, including California GOP Reps. Jeff Denham, Darrell Issa, Mimi Walters and David Valadao. Swing-district freshmen David Young, R-Iowa, and Bruce Poliquin, R-Maine, also switched positions on last week's vote. Each of them switched back Wednesday, joined by several other Republicans who opposed Maloney's plan last week.

The energy and water projects bill is the second spending bill for the upcoming budget year to come to the House floor.