Sen. Debbie Stabenow, D-Mich., left, accompanied by Sen. Gary Peters, D-Mich., and others discusses proposed legislation to help Flint, Mich. with their current water crisis, during a news conference, Thursday, Jan. 28, 2016, on Capitol Hill in Washington. (AP Photo/Alex Brandon)

Congress staved off an Oct. 1 government shutdown Wednesday, passing a stopgap spending measure after House Republicans agreed to address the drinking-water crisis in Flint, Mich., removing a major obstacle in negotiations.

The bill extends current government funding levels until early December, giving appropriators time to negotiate 2017 spending measures. It also provides year-long funding for veterans programs, $1.1 billion to address the Zika virus and $500 million in emergency flood relief for Louisiana and other states.

The House approved the bill in a 342-85 late-night vote, hours after senators voted 72-26 to pass the measure. Lawmakers have now recessed until after the Nov. 8 election.

Both the Zika and flood funding were subject to long and painstaking negotiations between majority Republicans and minority Democrats, but it was funding for Flint that threatened to push matters past the brink with one month before Election Day.

Democrats made clear earlier this week they would not support the spending bill unless Republicans moved to guarantee Flint aid, while GOP leaders countered the Senate had approved such help earlier this month in a separate water projects bill.

The impasse was broken late Tuesday after House Speaker Paul D. Ryan (R-Wis.) and Minority Leader Nancy Pelosi (D-Calif.) struck a deal allowing a vote to include $170 million in Flint relief to the House version of the water bill. That amendment and the underlying bill both passed the House Wednesday evening on bipartisan votes.

“We have sent a message of hope to the people of Flint,” Pelosi said Wednesday. “While we preferred to deliver those funds to the children in this [spending] bill, we are at least on a path to meaningful action.”

Ryan, addressing the Economic Club of Washington Wednesday morning, said the amendment would “help unlock” the spending bill. “We should be able to move this through, I believe, before Friday,” he said.

By Wednesday morning, Senate Democrats were satisfied that, thanks to the House deal, Flint would be addressed once Congress returns after the Nov. 8 election.

“I am convinced that there is going to be help for Flint in the lame duck,” Senate Minority Leader Harry M. Reid (D-Nev.) said on the Senate floor. “They’ve been waiting for help, they deserve help, and I am very happy it is going to come.”

The Flint crisis is now into its second year, with most households and businesses in the Michigan city still unable to use their lead-tainted tap water for drinking or cooking. A decision made by a state-appointed emergency manager to switch water sources led to the corrosion of water-supply pipes that now must be replaced at a cost of hundreds of millions of dollars.

The federal aid package passed by the Senate would fund a portion of those costs while also helping Flint and other communities deal with the public-health implications of lead exposure. The House version is less specific, authorizing the Army Corps of Engineers to undertake infrastructure repairs.

Wednesday’s Senate votes capped weeks of frustration for Republicans, who complained that Democrats had engaged in bad-faith spending negotiations aimed at keeping vulnerable GOP incumbents in Washington rather than on the campaign trail.

“It’s almost as if a few Democratic leaders decided long ago that bringing our country to the brink would make for good election-year politics, and then they’ve just made up the rationale as they go along,” Senate Majority Leader Mitch McConnell said Tuesday.

McConnell (R-Ky.) unveiled a stopgap spending measure last week that indulged several Democratic demands, including a meticulously constructed deal on Zika funding and the elimination of several contentious policy riders. But it did not incorporate the $220 million Flint aid package that passed the Senate as part of the water bill.

Democrats have sought federal relief money for the Flint crisis since January, and they are eager to get the funding passed into law. The issue has stirred resentments over the inequities in the treatment of a majority-black city, and it has stayed near the top of Democrats’ congressional agenda for months.

With Democrats demanding funding for Flint, the bill failed to advance Tuesday on a 55-to-45 vote. The procedural vote was retaken Wednesday after the House deal was struck.

While most Senate Democrats voted Wednesday to advance the spending bill, Michigan’s two Democratic senators voted against it, because Flint aid was not directly attached. But both senators, Debbie Stabenow and Gary Peters, praised the House deal for creating a more definitive path forward.

“Quite frankly, had we not all stuck together yesterday, we wouldn’t be here today talking about a House bill passing with language dealing with Flint,” Peters said.

Rep. Dan Kildee (D-Mich.), a Flint native who co-authored the House amendment with Rep. John Moolenaar (R-Mich.), said the agreement would “create a concrete commitment from both bodies of Congress to get aid to my hometown, for my hometown, to the president’s desk.”

“What happened in Flint was a failure of government at every level,” he said. “Congress can take its rightful place in fulfilling its obligation and its responsibility to help my hometown recover.”

All told, the short-term spending bill was a triumph for Democrats, who were able to exact numerous concessions from Republican leaders who were determined to avoid a distracting government shutdown in the middle of campaign season. That has prompted grumbling from House conservatives, in particular, and increased GOP pressure on McConnell and Ryan to draw a harder line when the stopgap expires in December.

Democrats accepted a partial victory on the Flint aid, which they preferred to be attached to the spending bill, because it is a must-pass measure that is guaranteed to become law.

The two chambers will have to resolve differences between the two water-projects bills in a process that might stretch into November or December. The deal struck Tuesday, however, should assure the final product will include Flint aid.

The GOP agreement to secure Flint funding was all but sealed late Wednesday when Rep. Bill Shuster (R-Pa.), chairman of the Transportation and Infrastructure Committee, publicly committed on the House floor to include it in the compromise bill that will be negotiated with the Senate.

“In 2016, no one — no one — should be afraid to drink the water that comes out of their tap,” Shuster said.

Correction: An earlier version of this story misreported the Senate vote passing the stopgap spending bill. A procedural motion passed 77-21 before the 72-26 vote on final passage.