Angry House conservatives voted down a routine spending bill Thursday in a fight over gay rights, underscoring the passions surrounding a social issue that is dividing the Republican Party and the nation in this election year.

The 305-112 vote killed a spending bill for energy and water projects, and may imperil GOP efforts to pass any more of the 12 annual appropriations bills for the upcoming budget year, work that is the most basic function of Congress.

Last year, the appropriations process derailed in similar fashion in a fight over the Confederate flag. Both outcomes illustrate that even as Speaker Paul Ryan tries to focus the House on producing a governing agenda and taking care of essential work like funding the government, social issues can sidetrack lawmakers and produce uncomfortable clashes within the GOP.

The implosion Thursday came a day after Democrats added an amendment to the energy and water bill protecting lesbian, gay, bisexual and transgender people from discrimination by federal contractors. The amendment, which passed on a 223-195 vote, was aimed at upholding an Obama administration executive order. But Republicans argued it represented an assault on religious liberties, since contractors might be required to make accommodations for gay or transgender people in violation of their own religious beliefs.

When the underlying bill came up for final passage Thursday, more than half of House Republicans went against their own leadership and voted "no."

"We have to protect the free exercise of religion. We didn't intend for this fight to be added to this appropriation. Nevertheless, it was," said Rep. Steve Russell, R-Okla. "Obviously you saw the result. We need to go back to the drawing board."

Democrats saw it differently.

"House Republicans' thirst to discriminate against the LGBT community is so strong that they are willing to vote down their own appropriations bill in order to prevent progress over bigotry," said Minority Leader Nancy Pelosi, D-Calif. "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."

Democrats overwhelmingly opposed the bill over a GOP provision they said defends North Carolina's transgender bathroom law and thus allows discrimination against the LGBT community. The Obama administration has filed suit against the North Carolina law and has threatened to take away federal funding for the state, and Republicans muscled through a provision to ensure that federal dollars are not taken away.

Ryan blamed Democrats for the outcome Thursday, even as other Republicans acknowledged that as the majority party they have the responsibility to get spending bills across the finish line. Several Republicans also suggested that Ryan's commitment to open floor procedures might have to be revisited.

"Early on I stood up here ... and said that some bills might fail because we're not going to tightly control the process and predetermine the outcome of everything around here. We'll, that's what happened here today," Ryan said.

"What we learned today is that the Democrats were not looking to advance an issue but to sabotage the appropriations process," he said.

Ironically, a Confederate flag amendment similar to the one that stopped the process last year was added to a different spending bill last week with little fanfare, but no sooner did Ryan dispense with that controversy than the gay-rights issue arose. Some of the more pragmatic-minded Republicans expressed frustration at finding themselves once again sidetracked onto a social issue.

"I've said it many times that I don't think it's on our party's best interests to get distracted by very contentious social and cultural issues. I would prefer to leave them alone," said Rep. Charlie Dent, R-Pa. "I guess what disturbs me most is that these types of issues distract us from the underlying objective."

The gay rights amendment, by Democratic Rep. Sean Patrick Maloney, New York's first openly gay congressman, caused chaos on the floor last week when it looked like it was going to pass on a different spending bill before Republicans started switching their votes against it amid cries of, "Shame! Shame!" from Democrats.

Several House Republicans and aides said the issue was proving divisive and emotional within their conference. Thursday morning, House Republicans began a regular closed-door meeting with the reading of a prayer, as usual. But this time, Rep. Rick Allen of Georgia quoted from the biblical book of Romans, including passages that seemed to listeners to relate to those who had supported the Maloney amendment, such as: "Men committed shameful acts with other men, and received in themselves the due penalty for their error."

Lawmakers and aides present said some people were intensely uncomfortable and some walked out. Allen's spokeswoman Madison Fox said the congressman made no reference to the amendment or the bill.

___

Associated Press writer Alan Fram contributed to this report.