Washington (CNN) The House of Representatives failed to pass a massive farm bill Friday as Republicans were unable to shore up support from their conservative members amid an ongoing party-wide fight on immigration, rebuking GOP House leaders' who had predicted it would pass just minutes before.

The vote was 198-213.

While Republican leaders said they were confident ahead of the vote, it was clear the bill was in jeopardy, and members of leadership could be seen on the floor holding last-minute negotiations, as conservative Republicans sought a promise of a vote on their preferred immigration bill.

As the bill went down, the mood on the floor became increasingly tense. It started early during a procedural step ahead of the final vote, where Speaker Paul Ryan, Majority Leader Kevin McCarthy, Whip Steve Scalise and Deputy Whip Patrick McHenry had a ongoing conversation with the conservative Freedom Caucus leaders Mark Meadows and Jim Jordan. McCarthy, Scalise and Jordan are among those considering becoming the next House speaker should Republicans maintain control over the House after the midterms when Ryan has announced he'll retire.

Leaving Ryan's office before the vote began, McCarthy had told reporters the farm bill would pass, adding conservatives will get their demand of a vote on their hardline preferred immigration bill -- authored by Virginia Republican Rep. Bob Goodlatte -- in June.

But as lawmakers ticked through the final amendment votes to the farm bill, Freedom Caucus leaders made clear in a huddle on the floor with GOP leaders that a future vote wasn't enough -- it had to be immediate -- before, even, the farm bill that was about to be considered, two sources said.

While Scalise continued to work on whipping members, Ryan walked to the back of the floor, leaned on a railing and looked on. At one point he made a motion of wiping his hands, as if to make clear he was done with the process for the day.

The conservative-driven bill -- which included the work requirements that Ryan has coveted and pushed for -- was, at least for now, dead, sunk not because of its actual content, but because of immigration, an issue that has roiled the Republican Party for years.

According to sources familiar with the negotiations, the House Freedom Caucus had been assured they'd get a vote on Goodlate's bill before the end of June, but it wasn't enough at the last minute. Moderates had also been assured they'd get a vote on a proposal they were still developing at the same time, a way to stave off an effort from some of their moderate colleagues to force an immigration debate on the House floor through a discharge petition.

Now, however, Jeff Denham, a Republican from California and the leader of the moderate effort to bring an immigration debate to the floor, said that the Freedom Caucus' effort had thrown the entire negotiation into jeopardy.

"I'm disappointed the farm bill came down, and I'm disappointed that some colleagues asked for a concession, got the concession and then took down a bill anyway," Denham said.

Denham also said the Freedom Caucus maneuver could encourage moderates to sign onto the discharge petition, the mechanism that would force an immigration debate on the floor. The Republicans only need five more members if every Democrat also signed on.

"I would say, given, the breaking of the agreement that was made today, you are going to see more Republicans that are frustrated and angry enough to sign onto something that they've never signed onto before," he said.

The other problem for GOP leaders in the effort to advance the farm bill was that they didn't have Democrats backing the legislation. Democrats rejected the farm bill out of opposition to those work requirements Ryan sought in the food stamps program, formally known as the Supplemental Nutrition Assistance Program, or SNAP.

As the final vote started, almost everyone on the Republican side had their eyes up on the big board that shows all votes by name. Democrats became increasingly excited as the bill was going down. As the vote hung open, some called for it to close, and Rep. Juan Vargas of California loudly heckled leadership, saying, "where's your regular order?" As the clerk asked if there were any more votes, Vargas said this was "just fine" with him, and the Democrats cheered when it was gaveled down as not passing.

Rank-and-file members were frustrated leaving leaving the floor. Florida Republican Rep. Mario Diaz-Balart, a moderate, said withholding their votes was the Freedom Caucus' "prerogative" but that they hurt farmers who are having one of the toughest years they've had.

"This is a big victory for Nancy Pelosi and her allies," Diaz-Balart said.

The deadline to pass a farm bill is September 30.

Republicans want to require more people to work in order to receive the SNAP benefits, extending the mandate to parents of school-age children and to those in their 50s. Democrats worry the new requirements will prove too onerous for some of the very beneficiaries in need of the assistance. Those who fail to work or enroll in job training could be locked out for up to three years.

President Donald Trump voiced support for the bill Thursday in a tweet.

Tomorrow, the House will vote on a strong Farm Bill, which includes work requirements. We must support our Nation's great farmers! — Donald J. Trump (@realDonaldTrump) May 17, 2018

"Tomorrow, the House will vote on a strong Farm Bill, which includes work requirements. We must support our Nation's great farmers!"

The 641-page bill also addresses a range of issues related to agriculture, such as livestock disaster programs, conservation, feral swine, farm loan programs and broadband services in rural areas, just to name a few.

Given that the Senate is working on its own version of a farm bill -- one that has a less stringent approach on SNAP -- it's a foregone conclusion that the House bill, should it pass, won't be the final say on the matter, with a possible House-Senate conference looming to hash out the significant differences.

"There could not be a better time to take action to help more people join our workforce," Ryan told reporters during a news conference Thursday. "That is why the farm bill that we are debating today is so critical. It sets up a system for SNAP recipients where if you are able to work, you should work to get the benefits. And if you can't work, we'll help you get the training you need."