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 expected 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.”

Story continues below advertisement.

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

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 Barack 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 on 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 on 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 forego 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.

Some lawmakers from hard-hit states are unhappy with the compromise, saying that it would result in a slight delay in processing aid to victims, and that the overall total of FEMA funding wouldn’t be enough to account for the damage caused by the disasters.

“They would delay the process by punting back to the House,” said Sen. Roy Blunt, R-Mo. The deal “also stripped $1 billion in disaster relief and provides less emergency funding for Missourians in the wake of record flooding and tornadoes,” he added.

The debate over the budget bill turned on sharp — and familiar — political lines that scuttled earlier talk that the two parties were going to tone down their attacks.

Republicans, particularly House conservatives, said they were unwilling to add to the federal deficit, even for disaster funding, and accused Democrats of overspending. Democrats used the debate to portray Republicans as “holding hostage” relief checks for those struck by tornadoes, flooding, forest fires and droughts, focusing much of their criticism on House Majority Leader Eric Cantor (R), who represents Mineral, Va., the epicenter of the earthquake.

Although the agreement lifts the imminent specter of a government shutdown, it will not resolve the underlying fight over how much FEMA needs to help disaster victims and whether that money must be offset with spending cuts.

The White House has said FEMA will need $4.6 billion for the next fiscal year — a figure many Democrats say underestimates the agency’s needs.

Democrats will push to fully fund FEMA’s request and perhaps broaden it during negotiations over spending for the rest of the year, but they were split Monday night over what the compromise would mean for future funding battles.

“This is a very big and important move. It says we met each other halfway. We saved the jobs,” said Sen. Barbara Boxer (Calif.), referring to the the auto loan program. “We figured out a way to fund FEMA that was acceptable to them. It’s a template. We have to figure out how to meet each other halfway here.”

But Sen. Patrick J. Leahy (Vt.), whose state was hit hard by flooding from Hurricane Irene, said the deal would solve the disaster issue — but only temporarily.

“I’m concerned about the fact that we give blank checks to Iraq and (Afghanistan) and we don’t want to take care of America for Americans,” he said. “It’s wrong, it’s foolish and it will come back to haunt us.”