US President Donald Trump has signed a $1.3trn spending measure averting a government shutdown at midnight, acting just hours after saying he was considering a veto.
Mr Trump complained that the legislation does not fully fund his plans for a border wall with Mexico and does not address some 800,000 "Dreamer" immigrants who are now protected from deportation under a programme that he has moved to eliminate.
He said he signed it in order to provide needed money for the military.
Earlier, Mr Trump cast doubt on whether he would back the massive spending bill, saying he was "considering" a veto.
Then, adding to the made-for-TV drama, he scheduled a news conference.
Telegraphing the outcome, an internal White House television feed advertised the event this way: "President Trump Participates in a Bill Signing."
With Congress already on recess, Mr Trump had said on Twitter that he was weighing a veto.
I am considering a VETO of the Omnibus Spending Bill based on the fact that the 800,000 plus DACA recipients have been totally abandoned by the Democrats (not even mentioned in Bill) and the BORDER WALL, which is desperately needed for our National Defense, is not fully funded.— Donald J. Trump (@realDonaldTrump) March 23, 2018
He said that young immigrants now protected in the US under Barack Obama's Delayed Action for Childhood Arrivals "have been totally abandoned by the Democrats (not even mentioned in Bill) and the BORDER WALL, which is desperately needed for our National Defense, is not fully funded".
Several advisers inside and outside the White House had characterised the tweet as Mr Trump blowing off steam.
Mr Trump's tweet had been at odds with what top members of Mr Trump's administration and House Speaker Paul Ryan said on Thursday, and with a formal statement of administration policy, which said Mr Trump was supportive of the measure.
It came hours after the Senate passed the $1.3trn spending package aimed at keeping the government open past midnight.
Mr Trump has been increasingly frustrated with the media coverage of the bill, as conservative politicians and other critics have railed against it on cable news and in private calls.
His tweet was cheered by the conservative House Freedom Caucus, which voted against the spending bill along with two dozen Republicans in the Senate.
Representative Mark Meadows, chairman of the freedom caucus and a friend of the president, said in a tweet that the group would "fully support" a veto, adding that Congress should pass a short-term budget resolution while Mr Trump and congressional leaders "negotiate a better deal for the forgotten men and women of America".
The @freedomcaucus would fully support you in this move, Mr. President. Let's pass a short term CR while you negotiate a better deal for the forgotten men and women of America. https://t.co/Dj05V8hevl— Mark Meadows (@RepMarkMeadows) March 23, 2018
Senator Bob Corker also egged Mr Trump on.
"Please do, Mr. President," he tweeted. "I am just down the street and will bring you a pen. The spending levels without any offsets are grotesque, throwing all of our children under the bus. Totally irresponsible."
Please do, Mr. President. I am just down the street and will bring you a pen. The spending levels without any offsets are grotesque, throwing all of our children under the bus. Totally irresponsible. https://t.co/np7BmP1AkB— Senator Bob Corker (@SenBobCorker) March 23, 2018
"Make my day, Mr. President," taunted Representative Kurt Schrader.
Make my day, Mr. President. https://t.co/R6eJjORuCC— Rep. Kurt Schrader (@RepSchrader) March 23, 2018
The Senate passage of the bill averted a third federal shutdown this year, an outcome both parties wanted to avoid.
But the budget caps-busting deal drew serious conservative opposition.
It also failed to resolve the stalemate over shielding young Dreamer immigrants from deportation after Mr Trump's decision to end the Deferred Action for Childhood Arrivals programme last year.
While Mr Trump has repeatedly criticised Democrats over DACA, he cancelled the programme last autumn, ending the issuance of new DACA permits. A judge has forced the administration to continue issuing renewals.
The spending package includes $1.6bn for Mr Trump's long-promised border wall with Mexico.
The money was far less than the $25bn over 10 years Mr Trump had asked for as part of a last-ditch deal that would have included providing a temporary extension of the DACA programme.