WASHINGTON — 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-12 and the House is likely to ratify next week, is expected to keep federal agencies open until Nov. 18.

“It will be a win for everyone,” said Majority Leader Harry M. Reid, D-Nev.

Minority Leader Mitch McConnell, R-Ky., called the plan “a reasonable way to keep the government operational.”

Aides to House Speaker John A. Boehner, R-Ohio, said he will support the compromise.

GOP Sens. Susan Collins and Olympia Snowe of Maine joined 22 other Republicans to vote for the compromise. But Snowe charged that what was on display Monday in Washington was “an utter lack of understanding what the American people want Congress to achieve. Mainers are tired of the unending partisan crises that threaten to shut down our government.”

Collins said that, “I am pleased that an agreement has been reached that avoids a government shutdown and provides FEMA with critical funding. The American people have made it clear that they want us to work together to resolve differences.”

The spending battle marked the third time this year that congressional acrimony has brought the government to the edge of calamity. In April, Boehner and President Obama reached a deal on funding for 2011 about 90 minutes before a government shutdown was to begin.

On Aug. 2, just hours before the deadline, Congress gave final approval to legislation lifting the government’s borrowing authority, averting a partial shutdown and the potential for a default on the federal debt.

Although this week’s fight ended with days, rather than hours, to spare, it drained many in Congress, who thought it was a senseless fight. Reid summed up the feeling of many lawmakers when he quoted Sen. Johnny Isakson, R-Ga., who said there was too little money in dispute to raise the specter of a shutdown and to halt payments to those affected by natural disasters.

“Let’s fight when there’s something to fight about,” Reid quoted Isakson as saying during a speech on the Senate floor.

At issue was a dispute over how to fund disaster relief, a concern that was heightened in late August after an earthquake struck central Virginia and Hurricane Irene caused flooding in the Northeast.

Although Democrats said the Federal Emergency Management Agency needed more funding, they agreed to accept a Republican plan to spend $3.65 billion in disaster relief money, $1 billion of which would have gone toward the budget for the current fiscal year, which ends Friday. Republicans, concerned about adding to the federal deficit, refused to support the funding unless it was accompanied by $1.5 billion in cuts. They targeted an auto loan program popular with Democrats, leading to the standoff.

The showdown between the two sides was averted Monday when FEMA said it could make ends meet through the end of the week. That led to an agreement that calls for the agency and other government disaster relief programs to forgo the $1 billion in proposed funding for this week. Beginning Saturday and running to Nov. 18, FEMA can begin to tap the remaining $2.65 billion for ongoing efforts.

With the House out of session this week, the Senate approved a resolution that will keep the government open through next Tuesday. The House is expected to approve that extension in a voice vote Thursday, which does not require all members to be present, and then approve the longer-term bill next Tuesday.