Sen. Joe Manchin, D-W.Va., speaks to reporters as he walks towards the Senate as Congress moves closer to the funding deadline to avoid a government shutdown on Capitol Hill in Washington, Thursday, Jan. 18, 2018. (AP Photo/Andrew Harnik)

WASHINGTON (AP) — A divided House on Thursday passed an eleventh-hour plan to keep the government running. 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, though a source familiar with the discussion said Ryan didn’t guarantee an immigration vote. That person was not authorized to speak publicly about the private negotiations and spoke on condition of anonymity.

Just 11 Republicans, mostly conservatives and a pair of moderate Hispanic lawmakers, opposed the measure. Six Democrats, a mix of Hispanic and moderate legislators, backed the bill.

But most Senate Democrats and some Republicans were expected to vote no in that chamber, probably Friday. Democrats were hoping to spur slow-moving talks on protecting young immigrants who arrived in the U.S. illegally from deportation. A handful of Republicans, including Sen. Lindsey Graham, R-S.C., were pressing for swifter action on immigration and a long-sought Pentagon spending boost.

Senate rejection would leave the pathway ahead uncertain with only one guarantee: finger-pointing by both parties, which began as that chamber debated the measure.

Senate Majority Leader Mitch McConnell, R-Ky., accused Democrats of a “fixation on illegal immigration,” which he said “has them threatening to filibuster spending for the whole government.”

Senate Minority Leader Chuck Schumer, D-N.Y., who’s tried using opposition to the bill as leverage to prod immigration negotiations, called for a plan to finance government for just a few days, and said party leaders should try to quickly reach an agreement. He said that should be done with or without President Donald Trump, who initially expressed support for a bipartisan effort to address the issue, only to oppose one proposed by several senators.

“How can you negotiate with the president, who has to sign the legislation, is like a sphinx on this issue, or says one thing one day and one thing the next?” Schumer asked.

The GOP controls the Senate 51-49 and will need substantial Democratic backing 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.

“Senator Schumer, do not shut down the federal government,” said Ryan, adding, “It is risky. It is reckless. And it is wrong.”

Underscoring the political stakes, McConnell warned GOP senators in an email obtained by The Associated Press that voting against the measure “plays right into Democrats hand” — presumably because it would dilute the argument that Democrats killed the legislation.

Democrats said voters would fault Republicans because they control Congress and the White House. They also noted that Trump rejected 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.

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 children’s health program and delaying some taxes imposed by President Barack Obama’s health care law. The health program insures nearly 9 million low-income children, and some states have nearly exhausted 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.”

Democrats want 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, and he and Republicans want any immigration deal to include money for the president’s promised wall along the Mexican border and other security measures..

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.