The rancorous political debate over sexual identity unexpectedly prompted the Republican-controlled House of Representatives to rejected an energy and water spending bill on Thursday after Democrats attached an amendment to protect the rights of transgender people.

The legislation, which would have funded the U.S. Army Corps of Engineers and the Department of Energy in the fiscal year that starts Oct. 1, failed on a 112-305 vote, with 130 Republicans and 175 Democrats opposing the legislation.

The vote outcome was such a surprise that the House Appropriations Committee initially announced that bill had passed and was forced to retract the statement.

Democrats blamed Republicans for opposing a Democratic amendment to bar federal contractors from government work if they discriminated against the lesbian, gay, transgender and bisexual (LGBT) community. Democrats were unable to attach the same measure to a separate House spending bill last week.

"In turning against a far-reaching funding bill simply because it affirms protections for LGBT Americans, Republicans have once again lain bare the depths of their bigotry," House Democratic leader Nancy Pelosi said in a statement.

Republicans zeroed in on the fact that Democrats voted against the bill by 6-175 even though they succeeded in attaching the LGBT amendment to it.

House Speaker Paul Ryan accused Democrats of working to "sabotage the appropriations process," telling reporters: "The mere fact that they passed their amendment but voted against the bill containing their amendment proves this point."

The White House had already threatened to veto the legislation, and Democrats said on Thursday that it contained a number of "objectionable riders" including three provisions that they said would undermine the Clean Water Act and another that would allow people to carry arms on Army Corps of Engineers land.