Updated on January 18 at 10:02 p.m. ET

The House on Thursday evening narrowly passed a bill that would keep the federal government open for nearly another month amid an impasse over immigration. But the proposal may be doomed in the Senate, where Democrats and a small contingent of Republicans could block the bill and send the government into a shutdown beginning at midnight Friday.

After an anxious day of arm-twisting and negotiations, Republican leaders were able to persuade enough of their members to go along with a stopgap bill many in the party plainly despised. Rather than fund the government for the rest of the fiscal year, it merely kicks the budget debate forward another month. In a largely futile bid for Democratic support, the bill reauthorizes the Children’s Health Insurance Program for six years. But it lacks several other Democratic priorities, most notably a permanent legal status for young immigrants who face the threat of deportation once President Trump ends the Deferred Action for Childhood Arrivals program in early March. A group of Democrats voted for the measure, known as a continuing resolution, only after it was clear that Republicans were going to be able to pass it on their own. The bill passed, 230 to 197, with 11 Republicans voting against it and six Democrats voting for it.

The bigger drama for much of the day was whether a collection of defense hawks, along with conservatives in the House Freedom Caucus, would band together to sink the bill on the Republican side. Complicating the leadership’s effort was Trump himself, who tweeted in the morning his opposition to including a long-term extension of CHIP in a short-term spending bill. The White House was later forced to clarify that the president supported passage of the bill to avert a shutdown.

Representative Mark Meadows of North Carolina, the Freedom Caucus chairman, told reporters that Speaker Paul Ryan and his team lacked the votes to pass the bill and that his group was demanding concessions from the leadership. But GOP leaders said otherwise. “We’ll have the Republican votes to pass it,” Representative Patrick McHenry of North Carolina told reporters midway through the afternoon. He said the party whip, Representative Steve Scalise of Louisiana, had been calling GOP lawmakers from the hospital, where he is recovering from another surgery after being shot and seriously wounded at a congressional baseball practice last year. When a member gets a call from a hospital bed, McHenry said, “it kinda works.”

Yet all of the whipping by the House leadership had little effect on the Senate. During a tense floor debate late Thursday evening, Senate Minority Leader Charles Schumer pushed for an immediate vote on the House bill. “We all know it will be defeated,” he said. Democrats said they had secured enough support among their 49 members to block the bill from receiving the necessary 60 votes to defeat a filibuster. But Senate Majority Leader Mitch McConnell refused to hold the key vote until Friday, apparently hoping that a night’s sleep and the impending deadline would cause enough Democrats—and a few of his own resisting members—to relent.

Under pressure from liberals and immigrant activists, Democratic senators said they were prepared to take a stand against Trump’s opposition to a bipartisan deal to extend DACA and provide a path to citizenship for the Dreamers, who were brought to the United States illegally as children. “We will support a short-term CR for a few days to keep the government open while we stay in town and conclude our negotiations. But we do not support perpetuating the current budgetary dysfunction that is hurting our country and our Commonwealth,” Virginia Senators Mark Warner and Tim Kaine said in a joint statement.

Democrats used Trump’s words to defend their position, pointing to his tweet last May saying the country needed “a good ‘shutdown’” and his more recent comments suggesting a shutdown was all but inevitable. Republicans, meanwhile, said the Democratic position was “unconscionable” and held paychecks for military-service members hostage to an immigration deal. “There’s no excuse for them to vote to shut the government down,” Senator Lamar Alexander of Tennessee told reporters. “So I think the American people will see that and be disgusted with all of Washington, and especially those who voted to shut it down.”

Still, the GOP was undermined by its own disunity. Senators Lindsey Graham of South Carolina and Rand Paul of Kentucky vowed to vote along with Democrats against the House bill, as did Senator Mike Rounds of South Dakota. “We are in a position right now where we are simply kicking the can down the road and the defense of our country is at risk,” Rounds said. “In its current form, I can’t support the [continuing resolution] but I’m open for discussions about how we can repair it.”

Rounds and other senators raised the possibility of voting for an even shorter stopgap bill that would avert a shutdown and give party leaders at least a few more days to negotiate a broader deal on immigration and spending. But it’s unclear whether top Republicans would go for that.

In an ominous sign for the negotiations, talk increasingly turned on Thursday from ways to prevent a shutdown to which party would be to blame if one occurred. “If the government shuts down, they’ll believe that we’re all idiots,” GOP Senator John Kennedy of Louisiana told reporters, even as he personally said it would be the fault of Democrats pushing for “amnesty” for undocumented immigrants.

Other Republicans were more resigned to history. Polls showed the public blamed the GOP for the shutdowns in 1995 and 2013. This time, Senator Orrin Hatch of Utah suggested, would be no different. “We always get blamed for it even when it’s their fault,” he lamented.