Donald Trump veered toward a shutdown of the federal government by vowing not to sign a stopgap spending bill passed by the Republican majority in the Senate, taking his colleagues by surprise and catching many legislators who have already left town for the holiday break unawares.

Trump, at a signing ceremony at the White House for unrelated legislation, said: “I’ve made my position very clear. Any measure that funds the government must include border security – has to.

“Not for political purposes but for our country, for the safety of our community. It is our sacred obligation. We have no choice.”

Scrambling to keep up with the president, Republicans in the House of Representatives late on Thursday passed a remade spending bill with $5.7bn for Trump’s wall built in.

But with many senators having left town and a narrow Republican majority in that chamber to begin with, it seemed highly unlikely that the Senate would be able to take up and pass the legislation for Trump’s signature in advance of a spending deadline of Friday at midnight.

A spokesman for the Senate majority leader, Mitch McConnell, said on Thursday night that his colleagues would begin consideration of the new bill on Friday afternoon, but noted that expedited consideration would require the consent of all senators. Given Democratic opposition to Trump’s wall, that would be extraordinary.

A failure by Republicans in the Senate to pass the bill would prompt a shutdown. Trump will not travel to his Florida resort home of Mar-a-Lago as planned on Friday if there is a government shutdown, the White House press secretary, Sarah Sanders, told reporters.

Trump had sought to insert $5bn in funding for a border wall with Mexico into successive spending resolutions, but to this point his Republican colleagues in control of Congress had resisted. In the current impasse, it was unclear whether Trump would be willing to sign a bill including less wall funding than that.

US government shutdown: what is it, will it happen and who's to blame? Read more

Trump had been under pressure to hold out for wall funding from far-right commentators such as Ann Coulter and Rush Limbaugh, who said on his show Thursday, “They just broke Trump! Trump’s finished. They’re dancing on the grave already. They’re celebrating.”

Play Video 1:05 ‘I am proud to shut down the government’, Trump tells Schumer – video

Trump made a border wall the central plank of his 2016 candidacy and in advance of last month’s midterms the president placed opposition to immigration and smears against immigrants at the center of his campaigning activity. Republicans lost 40 seats in the House in the midterm elections.

Critics of Trump’s proposal for a border wall, including Republicans, say it would not increase security or stem drug flows while costing more than technology- and personnel-based measures that would be more effective.

But the lateness of Trump’s play made it unlikely that he would get what he was demanding without a shutdown first. Trump himself was scheduled to fly to his Florida resort home of Mar-a-Lago on Friday for a trip that could last more than two weeks, according to federal aviation authority advisories.

Paul Ryan, who bit his lip as Trump ran wild, says goodbye to politics Read more

Trump signaled his move with a tweet Thursday morning. “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!” the president wrote. “We foolishly fight for Border Security for other countries - but not for our beloved U.S.A. Not good!”

The president met House Republicans on Thursday after the Senate approved legislation temporarily to fund the government, which had been seen as a key step toward averting a government shutdown.

Unless the issue is resolved, more than 800,000 federal workers would face furloughs or be forced to work without pay, disrupting government operations days before Christmas.

On Thursday morning, Trump attempted to deflect criticism from both sides.

Judge blocks Trump policy denying asylum for gang and domestic violence victims Read more

“With so much talk about the Wall, people are losing sight of the great job being done on our Southern Border by Border Patrol, ICE and our great Military. Remember the Caravans? Well, they didn’t get through and none are forming or on their way. Border is tight. Fake News silent!” the president tweeted.

In a tweet a few minutes earlier, Trump appeared to acknowledge that his long-promised “big, beautiful wall” hasn’t happened and isn’t being funded. Most of the existing border barrier consists of fencing.

Many of Trump’s supporters were frustrated that he appeared to retreat on his shutdown threats after promising a fight over the wall, which had been central to his presidential campaign. Just last week Trump said he would be “proud” to shut down the government over his demand for $5bn for the wall.

The Republican congressman Mark Meadows, a leader of the conservative House Freedom Caucus, said Trump’s political base “will just go crazy” if he signs a bill without wall funding. He warned it will be tougher to win the money next year when Democrats control the House. He said supporters of the president “believe it’s a promise that he’s been telling them that he will keep”.