House Speaker Paul Ryan of Wis. meets with reporters on Capitol Hill in Washington, Thursday, May 12, 2016, following his meeting with Republican presidential candidate Donald Trump. (AP Photo/Cliff Owen)

House Speaker Paul D. Ryan finds himself in the middle of yet another Republican civil war as the battle over LGBT rights has come to Congress, threatening to divide an already fractured GOP.

It is a fight the speaker does not want to have — especially in a competitive election year in which presumptive GOP presidential nominee Donald Trump’s candidacy is already tearing the party apart.

The fight escalated on Thursday when shortly before an expected vote over an energy and water spending bill, House Republicans held a private meeting in which many vented their frustrations over language passed late Wednesday to bar discrimination against lesbian, gay, bisexual and transgender employees of federal contractors, according to several people in the room.

The spending bill failed in a 305-to-112 vote — along with the LGBT language introduced by Rep. Sean Maloney, an openly gay New York Democrat.

Several GOP members were deeply upset after Rep. Rick Allen (R-Ga.) offered a prayer at their Thursday meeting implying that those who supported LGBT rights “on the floor last night” went against the teachings of the Bible, according to several people in the room. At least one member walked out after Allen’s comments, the people said.

“I thought the comments were wildly out of bounds and especially inappropriate given that this was supposed to be a prayer,” said Rep. Charlie Dent (R-Pa.).

Dent voted for the Maloney amendment both times and has been cited by Democrats as a key GOP ally in passing the measure.

A spokeswoman for Allen acknowledged that he led the prayer at the GOP meeting but said he “made no mention of the amendment or the bill.”

[House turns into a battleground over LBGT rights]

“It’s unfortunate because it’s a very good bill. . . . But what we learned today is that the Democrats were not looking to advance an issue but to sabotage the appropriations process,” Ryan (R-Wis.) said after the vote. “The mere fact that they passed their amendment and then voted against the bill containing their amendment proves this point.”

People in Thursday morning’s GOP conference meeting said Republican lawmakers expressed concerns about Maloney’s amendment, though some said that it would not be their reason for opposing the spending bill.

[Republicans pull measure from House floor that would roll back LGBT rights]

Ryan, those people said, emphasized that as part of his speakership, he was asked to follow regular order, which means allowing a free-flowing amendment process on the House floor. Now, Ryan faces a key test of his leadership as the entire budget process — passing multiple spending bills to fund the government — could be in jeopardy if Republicans balk at allowing an open process.

Republican opposition was not the only thing to sink the spending bill. Democrats are also upset about language attached Wednesday night regarding Iran’s nuclear capability and other proposals introduced by Rep. Bradley Byrne (R-Ala.) regarding LGBT students and Rep. Robert Pittenger (R-N.C.) to block the federal government from punishing North Carolina for its new law preventing transgender people from using bathrooms corresponding to their gender identity.

Democrats won an opening salvo late Wednesday when the House approved on a vote of 223 to 195 Maloney’s measure denying payment to federal contractors who discriminate against LGBT employees. Maloney had proposed such language before, but it was defeated last week on the House floor, with Democrats accusing Republican leaders of pressing their members to switch votes at the last minute.

“Equality wins! We have a long way to go, but achieved big victory. Will keep fighting until every #LGBT American is safe, can pursue dreams,” Maloney tweeted.

But after Maloney’s defeat Thursday morning, it is clear conservatives will continue to wage their fight.

Conservatives are mainly taking aim at a pair of directives by President Obama to ensure protections for LGBT employees of federal contractors and to ensure public schools provide access to locker rooms and bathrooms that correspond with students’ gender identity. Also on Wednesday, Byrne’s measure passed to exempt religious groups from complying with the directives.

[Eleven states sue Obama over bathroom guidance to public schools]

“We live in complicated times,” said the chairman of the Republican Policy Committee, Rep. Luke Messer (R-Ind.), who has proposed language to block Obama’s public school guidance. “These are the debates of our nation, and I think it’s important as a member that we respond to them.”

Republican leaders have tried to steer lawmakers away from wading into the hot-button debate. But with LGBT issues already boiling in the states, social conservatives seem eager to take up the cause by seeking to attach an array of religious-exemption measures to must-pass spending bills, a move that could seriously gum up the budget process.

Earlier this week, House leaders cautioned Republicans at a closed-door session that Democrats were likely to keep trying to force them into uncomfortable votes on LGBT discrimination, according to aides and members who were present. Ryan floated the idea of modifying House rules in a way that might restrict the number of amendments that could be offered on the floor, which would allow leaders to get out ahead of controversial votes and avoid any potentially embarrassing floor fights.

Democrats, meanwhile, are exploiting the GOP divide.

“Democrats are being given a huge opportunity to put Republicans on the record on issues that alienate most independent, moderate voters,” Rep. Steve Israel (D-N.Y.), a former Democratic Congressional Campaign Committee chairman, said in an interview. “Every time that Republicans give us the opportunity, we’re going to take it.”

Conflict erupted in the House on May 19 after Republican leaders successfully whipped their members to vote down a Democratic amendment. The amendment would have protected presidential executive orders on non-discrimination for LGBT contractors. (Thomas Johnson/The Washington Post)

But some Republicans are undeterred, with Rep. Trent Franks (R-Ariz.) saying,  “If they drive the bulldozer at us, we have to push back.”

The GOP leadership is trying to “thread the needle,” as aides put it, between conservatives itching for another chance to challenge Obama and those who don’t want to tackle an issue they think is best left for the states to resolve. But that is not an easy task, since Republicans disagree on whether LGBT rights should be protected at all.

“There’s a claim of discrimination, and I don’t think we’ve had the debate,” said Rep. Dave Brat (R-Va.). “Is there another set or class of rights that need to be defined in law?”

Brat was one of several Republicans who said the bathroom guidelines were another example of Obama overstepping his executive authority by wading into everything from environmental policy to immigration.

“We’re going to begin, as appropriate, to challenge these formulations of federal policy that are really changing the fabric of business in this country,” said the House Rules Committee chairman, Rep. Pete Sessions (R-Tex.).

Democrats want to draw attention to the GOP infighting. Maloney’s measure prompted an emotional and testy shouting match on the House floor before its failure last week. The Democrat revived the measure on Wednesday night and it passed with 43 Republicans aboard.

Democrats see LGBT rights as a prime opportunity to prove that House Republicans are intolerant of minorities. The message fits with a broader effort to cast all Republicans as part of a party that has embraced Trump’s brash rhetoric about immigrants and Muslims.

“The question [Republicans] have to ask is if they want to align themselves with Trump and the states who want to go backwards,” Maloney said in an interview. “There is a majority the House of Representatives right now to oppose discrimination in the workplace.”

Democrats accused seven Republicans of switching their votes on the Maloney measure last week, causing an uproar after the bill seemed to have passed.

“We have more than enough votes,” Maloney said. “We actually won the vote even with some Democrats missing last week — the issue is that they rigged the vote.”

Ryan told reporters on Wednesday that the breakdown — in which Democrats shouted “Shame! Shame!” across the aisle at their GOP colleagues — was just a misunderstanding.

“A bunch of members were misled as to what the amendment was or was not,” Ryan said. “A lot of people thought it was about bathrooms and guidance letters. . . . There was a real concern that this was going to jeopardize critical funding for our veterans administration and the military.”

The situation resembles last year’s debate over the Confederate flag that dragged the spending process to a halt.

[House takes action against Confederate flag]

Then, Democrats successfully rallied support from moderate Republicans to ban the flag on federal property. Southern Republicans were enraged and threatened to vote against the overall bill, forcing then-House Speaker John A. Boehner (R-Ohio) to give up on the entire appropriations process to avoid an embarrassing failure.

Mike DeBonis and Karoun Demirjian contributed to this report.