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

The dome of the U.S. Capitol is seen through barren trees on a cold night in Washington January 12, 2016. REUTERS/Kevin Lamarque

The legislation, which would provide funds for 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 outcome was such a surprise that the House Appropriations Committee initially announced the 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 discriminate against the lesbian, gay, bisexual and transgender (LGBT) community. Democrats failed 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.

But Republicans accused Democrats of working to sabotage the House appropriations process by voting 6-175 against the bill after they had succeeded in amending it.

House Speaker Paul Ryan said his own decision not to keep legislation under tight control had created conditions for “more amendments from both sides of the aisle ... and, yes, more unpredictability.”

“That’s what happened here today. It’s unfortunate, because this is a very good bill,” Ryan said. He vowed to continue pushing the energy and water bill, along with other appropriations measures.

Democrats said they opposed two Republican amendments. One would prevent Washington from witholding federal funds from North Carolina over its law on LGBT bathroom use. The other would have stopped the Democrats’ LGBT amendment from affecting religious workplace exemptions.

The White House had already threatened to veto the legislation over other provisions that Democrats said would undermine the Clean Water Act.