Recent history suggests Congress, when facing a shutdown deadline, waits until literally the last day before settling on a resolution. This week, then, represents a modicum of progress — lawmakers struck a deal with four days to spare.

Senate leaders agreed to a deal Monday evening that is almost certain to avert a federal government shutdown, a prospect that had unexpectedly arisen when congressional leaders deadlocked over disaster relief funding.

After days of brinkmanship reminiscent of the budget battles that have consumed Washington this year, key senators clinched a compromise that would provide less money for disaster relief than Democrats sought but would also strip away spending cuts that Republicans demanded. The pact, which the Senate approved 79 to 12 and the House is expected to ratify next week, is expected to keep federal agencies open until Nov. 18.

House members left town on Friday, but House Speaker John Boehner’s (R-Ohio) office said the GOP leadership will accept the compromise.

Whenever there’s a dispute like this, the question invariably turns to who blinked, since everyone wants to try to save face. Republicans are arguing that the deal includes less short-term funding for FEMA, which means the GOP got what it wanted. But insofar as the larger fight was over offsets, Democrats, by being far more combative than usual, have reason to be pleased — they insisted that disaster aid not be subjected to offsets, and in this agreement, they’re not.

Word yesterday afternoon that FEMA’s bank account had enough funds to get the agency through the week immediately changed the nature of the debate, with Republicans losing some leverage.

It cleared the way for the deal: FEMA’s coffers will be replenished this weekend, with the start of the new fiscal year, with enough funding to hold the agency over through mid-November. The larger stopgap spending bill then passed the Senate easily, with only 12 members voting against it (all conservative Republicans), and another measure, keeping the government’s lights on from Saturday to Tuesday, passing on a voice vote. The House will approve the four-day extension on in a pro-forma session this week, and is expected to pass the larger spending measure when members return on Tuesday.

It’s worth noting, by the way, that the deal struck last night is practically identical to the compromise House Minority Leader Nancy Pelosi (D-Calif.) sketched out last week. It’s almost as if Pelosi knows what she’s doing when it comes to the lawmaking process.

I’d note just two other angles to keep in mind. First, I’m delighted that a deal was reached — shutdowns don’t do anyone any favors — but no one should mistake the agreement as evidence of an effective legislative branch of government. As we discussed last week, no one should be impressed when Washington manages to somehow keep the lights on. The fact that a shutdown was even a possibility this week only reinforces fears that Congress is simply hopeless — lawmakers shouldn’t struggle to complete the most basic tasks, and avoiding shutdowns need not be deemed an accomplishment.

And second, all of this hullabaloo was over a spending measure that only funds the government for about six weeks — at which point we will, of course, have yet another threat of a shutdown. I’ll have more on that story coming up this morning.

Our ideas can save democracy... But we need your help! Donate Now!

Follow Steve on Twitter @stevebenen. Steve Benen is a producer at MSNBC's The Rachel Maddow Show. He was the principal contributor to the Washington Monthly's Political Animal blog from August 2008 until January 2012.