President Joe Biden signed into law the stopgap bill to avert a government shutdown passed by Congress just hours ahead of a critical midnight deadline when funding for federal agencies was set to run out. The Senate passed the measure Saturday evening after the House abruptly reversed course earlier in the day and passed a bipartisan bill to extend government funding after days of uncertainty over whether a shutdown could be averted. “Tonight, bipartisan majorities in the House and Senate voted to keep the government open, preventing an unnecessary crisis that would have inflicted needless pain on millions of hardworking Americans,” Biden said in a statement Saturday. He also slammed House Republicans for the last-minute scramble, adding, “We should never have been in this position in the first place.” The measure will keep the government open only through November 17 and includes natural disaster aid but not additional funding for Ukraine or border security. It also includes a measure to keep the Federal Aviation Administration operational. House Speaker Kevin McCarthy announced the stopgap proposal Saturday morning, a move that came after weeks of infighting among House Republicans and a failed effort to pass a GOP stopgap bill in the chamber. The bill passed the House with an overwhelmingly bipartisan vote. The decision by McCarthy to put a bill on the floor that would win support from Democrats could put his speakership at risk as hardline conservatives continue to threaten a vote to oust him from the top House leadership post. McCarthy was defiant after the vote, daring his detractors to try to push him out as he argued he did what was needed to govern effectively. “If somebody wants to make a motion against me, bring it,” McCarthy told CNN’s Manu Raju at a press conference. “There has to be an adult in the room. I am going to govern with what’s best for this country.” McCarthy suffered a high-profile defeat on Friday when the House failed to advance a last-ditch GOP stopgap bill – ramping up the pressure on him to decide whether to try to reach across the aisle to work with Democrats to keep the government open even if it would risk a backlash from conservatives. Hardliners are expected to force a vote to remove Kevin McCarthy as speaker, just “not yet,” according to a Republican lawmaker. The House is gaveled out until Monday so that is the earliest it could happen; then leadership would have two days to schedule the vote. The vote to pass the bill in the House came after a chaotic few hours as House Republicans met throughout Saturday morning, seesawing between options for how to proceed. Republicans, including veteran appropriators and those in swing districts, pushed to bring a short-term resolution to keep the government funded to the House floor for a vote Saturday. The Senate had been working to advance its own bipartisan stopgap bill and had been on track to take a procedural vote Saturday afternoon. But that was put on hold after the House moved quickly to pass the short-term funding extension – and senators coalesced around the House-passed bill. House Republicans had thrown cold water on the Senate’s bill, and GOP Sen. Rand Paul had vowed all week to slow that process beyond the midnight deadline over objections to Ukraine aid included in the Senate bill. But Paul told CNN on Saturday afternoon that he would not slow down the Senate’s consideration of the House-passed spending bill. A shutdown could have consequential impacts across the country, from air travel to clean drinking water, and many government operations would grind to a halt – though services deemed essential for public safety would continue. This story and headline have been updated with additional developments.