WASHINGTON — Hoping to defuse a Republican rebellion, Speaker Paul D. Ryan promised Thursday that House Republicans would draft compromise legislation on immigration, setting up a showdown on one of the thorniest political issues just as the midterm campaign comes into focus.

Conservative Republicans loath to loosen immigration rules remained at odds with moderates pressing to protect young immigrants brought to the country illegally as children, as Mr. Ryan and his fellow leaders in the House labored to reach an accord. And the deadline for an agreement could come within days.

Moderate Republican lawmakers need only three more signatures on a petition to force a series of immigration votes over the speaker’s objections, including at least two that would focus on those young immigrants, known as Dreamers. Because of the arcane rules for such “discharge petitions,” those lawmakers face a Tuesday cutoff to gather the 218 names needed to force floor action in late June.

“We have a firm deadline of Tuesday,” said Representative Jeff Denham of California, a leader of the petition drive. “Tuesday we will hit 218.”