WASHINGTON (AP) — A divided House voted Thursday to prevent a government shutdown after an eleventh-hour deal brought conservatives aboard. But the GOP-written measure faced gloomy prospects in the Senate, and it remained unclear whether lawmakers would be able to find a way to keep federal offices open past a Friday night deadline.

The House voted by a near party-line 230-197 vote to approve the legislation, which would keep agency doors open and hundreds of thousands of federal employees at work through Feb. 16. The measure is designed to give White House and congressional bargainers more time to work through disputes on immigration and the budget that they’ve tangled over for months.

House passage was assured after the House Freedom Caucus reached an accord with House Speaker Paul Ryan, R-Wis. The leader of the hard-right group, Rep. Mark Meadows, R-N.C., said Ryan promised future votes on extra defense spending and on a conservative, restrictive immigration bill. Meadows also spoke to President Donald Trump.

But most Senate Democrats and some Republicans were expected to oppose the measure when it reaches that chamber later Thursday. Democrats were hoping to spur slow-moving immigration talks, while a handful of Republicans, including Sen. Lindsey Graham, R-S.C., were pressing for swifter action on immigration and a long-sought boost in Pentagon spending.

Senate rejection would leave the pathway ahead uncertain with only one guarantee: finger-pointing by both parties.

The GOP controls the Senate 51-49 and will need a substantial number of Democratic votes to reach 60 — the number needed to end Democratic delaying tactics. Republicans were all but daring Democrats to scuttle the bill and force a shutdown because of immigration, which they said would hurt Democratic senators seeking re-election in 10 states that Trump carried in 2016.

“If there’s a government shutdown — and let’s hope there’s not — it’d be the Democrats shutting it down,” said Sen. Richard Shelby, R-Ala.

Democrats said voters would fault Republicans because they control Congress and the White House and because Trump shot down a proposed bipartisan deal among a handful of senators that would have resolved the conflict over how to protect hundreds of thousands of young immigrants from deportation.

“You have the leverage. Get this done,” House Minority Leader Nancy Pelosi of California said about Republicans.

Trump himself weighed in from Pennsylvania, where he flew to help a GOP candidate in a special congressional election.

“I really believe the Democrats want a shutdown to get off the subject of the tax cuts because they’re doing so well,” he said.

If the measure stalls in the Senate, the next steps were murky.

Barring a last-minute pact between the two parties on spending and immigration disputes that have raged for months, lawmakers said a measure financing agencies for just several days was possible to build pressure on negotiators to craft a deal. Also imaginable: lawmakers working over the weekend with a shutdown underway — watched by a public that has demonstrated it has abhorred such standoffs in the past.

Shadowing everything is this November’s elections. Trump’s historically poor popularity and a string of Democratic special election victories have fueled that party’s hopes of capturing control of the House and perhaps the Senate.

As he’s done since taking office a year ago, Trump was dominating and confusing the jousting, at times to the detriment of his own party. He tweeted that the month-long funding measure should not contain money for a children’s health insurance program — funds his administration has expressly supported — then the White House quickly said he indeed supports the legislation.

Congress must act by midnight Friday or the government will begin immediately locking its doors. Though the impact would initially be spotty — since most agencies would be closed until Monday — the story would be certain to dominate weekend news coverage, and each party would be gambling the public would blame the other.

In the event of a shutdown, food inspections and other vital services would continue, as would Social Security, other federal benefit programs and most military operations.

Hoping to garner more votes, Republicans added language providing six years of financing for the widely popular Children’s Health Insurance Program and delaying some taxes imposed by President Barack Obama’s health care law. The children’s health program serves nearly 9 million low-income children, and some states have come close to exhausting their funds.

But Pelosi compared the GOP bill to “having a bowl of doggy-doo and adding a cherry on top and calling it a chocolate sundae.”

Senate Majority Leader Mitch McConnell, R-Ky., taunted Democrats, saying, “My friends on the other side of the aisle do not oppose a single thing in this bill” and “can’t possibly explain” their opposition to voters.

Most Democrats remained opposed anyway, though saying they’d relent if there also was a deal to protect around 700,000 immigrants from deportation who arrived in the U.S. as children and now are here illegally. Trump has ended an Obama-era program providing those protections and given Congress until March to restore them.

Republicans were demanding that a separate budget bill financing government for the rest of this year include big boosts for the military, and they accused Democrats of imperiling Pentagon funding. Democrats were insisting on equally large increases for domestic programs for opioid treatment and veterans — efforts that many in the GOP also back.

While that tradeoff seemed achievable, it was the immigration dispute that loomed as the biggest hurdle, and Democrats were trying to use the need to keep government financed as leverage.

“If this bill passes, there’ll be no incentive to negotiate, and we’ll be right back here in a month with the same problems at our feet,” said Senate Minority Leader Chuck Schumer, D-N.Y.

Talks among top lawmakers and White House officials were moving slowly on an immigration package. Trump and Republicans want it to include money for the president’s promised wall along the Mexican border and other security measures.