WASHINGTON (AP) — For several hours Friday, in the stillness before dawn, the Senate appeared to have finally figured out how to fund most of the Department of Homeland Security before it faced the longest partial shutdown in U.S. history.

Senators handed House Speaker Mike Johnson, R-La., their deal and headed for the airports, seemingly confident of success.

Then it collapsed. Spectacularly.

An incensed Johnson marched out of his office Friday afternoon. He angrily rebuked the plan that the Senate had unanimously agreed to as a “joke.”

“I have to protect the House, and I have to protect the American people,” Johnson told reporters.

It was a dramatic denunciation of a deal that his counterpart, Senate Majority Leader John Thune, R-S.D., had negotiated after weeks of effort, and was the latest abrupt turn in a funding saga that has bedeviled top Republicans for much of the year.

The collapse of the deal leaves Congress, now on a two-week spring break, with no easy way out of the impasse that has put DHS into a shutdown since mid-February. It also has exposed a rare rupture between the two Republican leaders in Congress, testing their alliances as they labor to move another set of President Donald Trump’s priorities into law before the November elections.

Nothing ahead is likely to be easy. Thune had a deal with Democratic senators after negotiating for weeks on their demands for new restrictions on the department’s immigration enforcement work. Offers were traded several times. The talks moved along at a stop-start pace. Votes failed again and again.

Out of time and patience, senators essentially settled on a draw for the bill: They would not include funding for U.S. Immigration and Customs Enforcement (ICE) and for U.S. Border Patrol, while setting aside all the Democratic demands for new limits on the agencies.

Thune pointed out that Congress had allotted money for immigration enforcement and he told reporters that “we can get at least a lot of the government opened up again and then we’ll go from there.”

However, as House Republicans woke up to the news, their outrage was swift. Rep. Nick LaLota, R-N.Y., criticized the Senate’s decision, implying they gave in out of fear of political repercussions.

The bitter split threatens to complicate the ability for Republican leaders to achieve their objectives, particularly with significant tasks on the agenda including funding for the ongoing military action in Iran which could total more than $200 billion, among other strategic legislation.

Meanwhile, the rejection of the funding deal gives Democrats an opportunity to reiterate their claims about the partial shutdown being a result of Republican disunity.