WASHINGTON – A deeply divided House voted on Thursday to add $5 billion in border wall funding to a short-term spending bill, yielding to President Donald Trump’s demand for the money but casting further doubts upon the fate of efforts to avert a government shutdown.

The bill, which the House approved by a vote of 217-185, now heads back to the Senate, which must either approve the measure or risk shutting down a quarter of the government at midnight Friday. A Senate vote is expected Friday afternoon.

The House vote capped a drama-filled day that started with lawmakers anticipating quick passage of an already approved Senate funding bill, but then erupted into chaos when Trump announced he would not support the measure because it did not contain funding for the border wall – one of his signature campaign promises.

“I’ve made my position very clear: Any measure that funds the government must include border security,” Trump said at the White House.

At an Oval Office meeting a few hours earlier, Trump had informed House GOP leaders that he would not sign the Senate version, sending them scrambling to deliver new legislation that included $5 billion in border wall funding.

“We want to keep the government open, but we also want to see an agreement that protects the border,” said House Speaker Paul Ryan, R-Wis. “We have very serious concerns about securing our border.”

Lawmakers have until midnight Friday to pass a spending bill or funding will expire for a quarter of the federal government, triggering a shutdown heading into the holidays and forcing some 800,000 federal employees to go on furlough or work without pay.

More:A look at what public services will – and won’t – be interrupted if there is a government shutdown going into holidays

Congress is trying to end the budget stalemate and avert a government shutdown by piecing together a short-term measure that would keep the funds flowing through early next year.

The Senate voted Wednesday night to approve a short-term spending bill offered by Senate Majority Leader Mitch McConnell, R-Ky., that would fund the government through Feb. 8 but would delay any decision on border wall funding until next year.

But hardline conservatives in the House revolted because the Senate bill did not include Trump’s border funding, even though he had insisted during the presidential campaign that he’d make Mexico pay for the wall. Trump’s announcement that he would not sign the Senate measure sealed its fate.

The House responded by introducing its own spending package that also would fund the government through Feb. 8, but would include $5.7 billion for a border wall and nearly $8 billion in disaster relief to compensate communities hit hard by this year’s hurricanes and wildfires.

Trump tweeted his approval of the how the House voted by specifically thanking Republicans for their work.

"So proud of you all. Now on to the Senate!," Trump tweeted.

The border funding in the House proposal won’t be enough to build the wall but will improve border security, said Rep. Tom Cole, R-Okla.

“This is about keeping America safe – it’s not a complicated vote,” said House Majority Whip Steve Scalise, R-La.

Democrats accused Republicans of catering to a “Trump Twitter tantrum” and warned that the House bill would be dead on arrival in the Senate.

“This is a sham and a shame,” said Rep. Sheila Jackson Lee, D-Texas.

Hardline conservatives in the House Freedom Caucus insisted now is the GOP’s last chance to deliver on Trump’s campaign promise to build a border wall since Democrats will resume control of the House in January and their leader, Nancy Pelosi, will return as speaker.

“We’ve been telling the American public that we were going to fight, they have no reason to believe us now,” said Rep. Paul Gosar, R-Ariz., a Freedom Caucus member.

Said Freedom Caucus member Scott Perry, R-Penn.: “We made a promise to the American people to secure the border. This is our last chance. Nancy Pelosi will not do this.”

The uncertainty over the funding bill – and the chaos that ensued – was heightened by Trump’s constantly shifting position on the legislation.

Last week, Trump boasted during an Oval Office meeting with Democratic leaders that he would be “proud” to shut down the government over border funding and that he’d be willing to take the blame for any fallout.

But on Tuesday, the White House signaled that Trump was looking for other ways to fund a border wall and that he might be willing to sign a short-term spending bill that did not include the money.

Thursday morning, Trump took to Twitter and posted a message about his demands for a border wall funding but did not specifically comment on the Senate’s short-term bill.

“When I begrudgingly signed the Omnibus Bill, I was promised the Wall and Border Security by leadership. Would be done by end of year (NOW). It didn’t happen! We foolishly fight for Border Security for other countries - but not for our beloved U.S.A. Not good!” he wrote.

By the time House GOP leaders headed to the White House for their emergency meeting with Trump, it was clear he had changed his mind.

“At this moment, the president does not want to go further without border security, which includes steel slats or a wall,” White House spokeswoman Sarah Huckabee Sanders said. “The president is continuing to weigh his options.”

Following the meeting with Republicans, Sanders issued another statement saying that "not surprisingly, they all feel strongly about border security – stopping the flow of drugs, stopping human trafficking, and stopping terrorism."

"We protect nations all over the world, but Democrats are unwilling to protect our nation," she said. "We urgently need funding for border security and that includes a wall."

Back on Capitol Hill, Pelosi and Senate Minority Leader Chuck Schumer, D-N.Y., said Democrats have no intention of approving money for a border wall.

"In terms of wall funding, that’s a non-starter," Pelosi said.

Congress is scrambling to pass a short-term spending bill because lawmakers still haven’t passed seven of the 12 appropriations bills that are needed to fund the government for the fiscal year that began Oct. 1.

The seven remaining bills would fund nine departments – Agriculture, Commerce, Justice, Homeland Security, Interior, State, Transportation, Treasury and Housing and Urban Development – as well as several smaller agencies. Those are the departments and agencies that would be impacted by a government shutdown.

Contributing: Eliza Collins

More:Americans' message to Washington on the looming shutdown: Don't

More:Another government shutdown? Congress has until Dec. 21 to pass a spending bill to keep the lights on

More:The Ghost of Shutdowns Past haunts latest talks to keep the federal government open