(CNN) Republicans leaders late Tuesday night managed to pull together a long-awaited immigration agreement that satisfied both moderates and conservatives in their ranks, just moments before a self-imposed but significant deadline expired for a moderate-led insurrection on the issue.

The deal involved an agreement to vote on two immigration bills next week -- a conservative proposal that is not expected to have enough support to pass and a to-be-written bill that leadership is drafting based on weeks of closed-door negotiations among the two wings of the party. The proposal is aimed at offering a solution for recipients of the expiring Deferred Action for Childhood Arrivals program as well as additional resources for border security.

It is yet to be seen if that latter bill -- right now solely an outline of the negotiations -- would even have the votes to pass the House among Republicans, as Democrats are not expected to support it. If it were to pass the House, the Senate has made no indication it would take up the bill, rendering the votes largely a political exercise.

Still, the promise of votes on the floor of the House in the summer before midterm elections was unthinkable just months ago, something that moderates claimed demonstrated that their procedural efforts to force a vote by petition, which fell just two members of Congress short of crossing its threshold, was still successful in forcing talks forward.

As the negotiations wore on Tuesday, discussions moved away from policy -- which had some general agreement but could take days more to sort out -- toward what would be enough to stop a procedural move that would force the issue to the floor at the end of June on moderates' terms.

"Members across the Republican Conference have negotiated directly and in good faith with each other for several weeks, and as a result, the House will consider two bills next week that will avert the discharge petition and resolve the border security and immigration issues," House Speaker Paul Ryan's spokeswoman AshLee Strong said late Tuesday. "The full conference will discuss tomorrow morning and we'll have more to share at that point."

The deal came after shuttle diplomacy between moderates and conservatives who met with leadership, then separately, then communicated with each other back and forth.

The late-night meetings were largely about the procedure for moving forward, even as a bill was a "week" away from being fully drafted, according to a leading conservative.

House Freedom Caucus Chairman Mark Meadows, a North Carolina Republican, emerged from the conservative meeting late Tuesday saying he'd talked to moderates about what conservatives could accept, offering a promise that his members would support a vote on the to-be-written negotiated bill if they got a vote on their preferred conservative bill.

"I think their concern -- and I don't want to speak for them because obviously they are very capable of speaking for themselves ... is if they turn off the discharge petition and then we voted against the rule, it would set them back to ground zero, and so I've tried to let them know the terms in which we could support a rule to move a bill moving forward," Meadows said.

Negotiations halt petition from crossing threshold

The deal was announced as the House floor gaveled out for the evening -- running out the clock on moderates' deadline on their discharge petition, a rarely used procedural maneuver they've been working on for months, which would bypass leadership and force a vote on four different immigration proposals. Under House rules, moderates needed to reach 218 signatures on their petition by Tuesday evening if they wanted to hold a vote by the end of June, but the remaining moderates had held off on signing in hopes that all parties could strike a deal.

If enough signatures were gathered in the coming days, the vote could still be scheduled for next month, but passing the deadline would have been a significant blow to moderates, who have threatened for weeks to deliver enough signatures.

The House gaveled out without a deal, as the remaining moderates who were considering signing on said they were satisfied by Ryan's promise.

"I spoke with Speaker Ryan today, who assured me that our conference will vote, as early as next week, on an immigration bill that will give certainty to DACA beneficiaries and secure our border," said Rep. Dan Newhouse, a moderate Washington Republican. "Given this significant progress, I will not sign the discharge petition today."

Newhouse said Ryan also promised a vote in August on a bill that would address immigrant guest worker visas, a major need for agriculture districts.

A deal emerges to offer a DACA solution

After a more than hourlong meeting with leadership Tuesday, moderate Republicans emerged cautiously optimistic that they were moving toward a deal that would bolster border security in exchange for a permanent solution for DACA recipients. President Donald Trump decided to end the program but it's been limbo amid court challenges.

Rep. Carlos Curbelo, a Republican from Florida, an original backer of the moderate discharge petition, said as he emerged from that meeting that all that was outstanding were "a couple minor issues ... of substance" and "some questions on process" -- a reference to the discussion about how to sequence votes.

"We think that at some point the group has to trust that the leadership has refereed these discussions for a number of weeks and that based on all the information that they have on the many points that we've agreed on, that they can begin putting a product together for consideration on the floor of the House," Curbelo said of moderates' deciding to hold off on the discharge petition.

Talks were stuck for weeks on the issue of what would happen to the young undocumented immigrants who came to the US as children that were protected under DACA, but in the past week there has been a growing consensus around a plan put forth by conservative Rep. Raul Labrador, an Idaho Republican, that would create a new kind of visa that would be usable by DACA recipients but also by other immigrants, thus not creating a "special" path to citizenship for only undocumented immigrants. Along with that proposal is billions for border security and a suite of legal changes that would give the government far more immigration enforcement powers. Also in order to create the new visa, there would be cuts to the current legal immigration quotas?, including in some family categories.

Key to the negotiations, said conservatives, was that the procedure for the votes would be free of "trickeration," as Meadows put it.

"If everything's on the up and up I think that straight rule vote will be OK -- but the rule's got to be straight, no funny business," said Pennsylvania's Rep. Scott Perry, a Freedom Caucus member who has been in the negotiations. "We want to be clear, we don't want any funny business."

In a statement after the announcement, Curbelo called the agreement a "major development" for immigration.

"For many years, and for different reasons, leaders from both parties have refused to allow the House to act to secure a future for young immigrants brought to our country as children, while making Americans safer and more prosperous by strengthening border security," Curbelo said.

Still, he said the discharge petition would be kept alive, for now, saying it was "vital our colleagues remain committed to the discharge petition" until the final details were inked on the compromise. Curbelo has repeatedly said the petition could have a window in July if moderates miss their chance in June.