Staring at a certain defeat, House Republicans canceled votes on their immigration compromise Thursday — an embarrassing setback for leaders who thought they had finally been able to wrangle some unanimity on an issue that has bedeviled them for years.

Lawmakers emerged from a closed-door evening meeting to say their new goal is a vote sometime next week, after they try to make tweaks to win over conservatives while keeping moderates on board.

The vote on the “moderate” compromise bill was postponed just hours after a more conservative bill failed in the House by a 231-193 vote. More than three dozen Republicans joined Democrats to kill the legislation.

SEE ALSO: Trump on immigration legislation: Democrats ‘RESIST!’ Republicans ‘PRODUCE’

Worried about a twin rejection on the same day, Republican leaders decided on a cooling-off period.

“The worst thing for us to do would be to fail,” said Rep. Tom Cole, Oklahoma Republican. “I think people desperately want to get to ‘yes.’”

At stake is the fate of hundreds of thousands of illegal immigrant “Dreamers,” stiffer border security and President Trump’s goals of limiting the chain of family migration and ending the visa lottery.

Republican leaders thought they had an agreement between conservatives and moderates, but the conservatives balked, saying the bill had too many mistakes and didn’t do enough to pressure businesses against hiring illegal immigrants.

The conservatives wanted the bill to require the use of E-Verify, the government’s currently voluntary system for electronically checking a new hire’s work eligibility.

But if E-Verify is added, farm-region lawmakers said, they have to see a guest-worker program for agriculture so farms won’t lose their workforce, much of which is unauthorized.

“While we’ve all been in negotiations for the last several weeks, we feel like we’ve continued these good discussions on, but two new issues came up,” said Rep. Jeff Denham, a California Republican who had been leading negotiations for the moderates.

“We’re going to spend the weekend, delay a vote [until] next week and see if we can come to a compromise on those two final issues,” Mr. Denham said.

Some conservatives are opposed to anything that includes a pathway to citizenship and are unlikely to be won over. But other conservatives say their support is winnable so long as the bill makes major strides in border security, including firm funding for Mr. Trump’s border wall.

Mr. Trump called in to the Republican meeting, looking to urge the bill along.

Attorney General Jeff Sessions and Homeland Security Secretary Kirstjen Nielsen weighed in earlier this week, making the case for the more moderate legislation.

But with success looking elusive, Republicans across the spectrum have begun to pin blame for failure on Democrats.

“Democrats have taken a walk on this thing,” said House Speaker Paul D. Ryan, Wisconsin Republican.

Mr. Trump was more pointed: “They don’t care about the children. They don’t care about the injury, they don’t care about the problems.”

Yet it’s disunity within the Republican ranks that has sunk every effort to pass broad immigration legislation in the House for more than a decade, and those divisions were on display Thursday.

Conservatives griped that they felt abandoned by their leaders. They pointed to the more conservative bill that failed Thursday and said if Mr. Trump, the administration and Mr. Ryan had put more effort behind it, they may have been able to pass it.

“They told us they were way short — what I saw today on the floor was 193 votes — that’s pretty darn close to what [we’d] need to pass that,” said Rep. Jim Jordan, Ohio Republican.

Centrist Republicans accused conservatives of abandoning the core of an agreement they thought they had reached.

Republican leaders had planned votes on two bills, both of them sponsored by Rep. Bob Goodlatte, Virginia Republican and chairman of the Judiciary Committee. One bill, written months ago, would have codified the Obama-era Deferred Action for Childhood Arrivals program into law, curtailed family migration, ended the diversity lottery, authorized the wall, boosted criminal penalties for illegal immigration, surged more resources to border enforcement and punished sanctuary cities.

The legal status for DACA recipients was too much for some conservatives, while the lack of a full pathway to citizenship was too little for some moderates.

Forty-one Republicans joined 190 Democrats in opposition.

“We’re not going to let hatred, bigotry and xenophobia prevail in this country,” said Rep. Zoe Lofgren, a California Democrat who helped lead opposition to the bill.

But the vote on the conservative bill did serve Republican leaders’ purposes by officially derailing the petition drive that moderates and Democrats launched to try to force debate on a Democrat-backed bill that would have combined a generous pathway to citizenship for perhaps 2 million illegal immigrants with promises of future border security.

That petition drive was tied to the conservative legislation, so by bringing the bill to the floor — even in defeat — the petition fell.

Some moderate Republicans said they could start another petition drive next month, though they would have an even bigger climb and only a couple of weeks to gather signatures before the next window for action closes.

• David Sherfinski contributed to this article.