The announcement in the White House Rose Garden on the bipartisan deal marked a retreat by Trump, suspending a row that paralysed Washington, disrupted air travel, and left more than 800,000 federal employees without pay for five weeks.
The Senate and House of Representatives both passed the deal by unanimous consent Friday. The White House later confirmed Trump had signed it into law.
The top Democratic senator, Chuck Schumer, said he hoped the president had "learned his lesson."
Trump's reversal came as the full weight of the shutdown, including the financial cost on struggling employees and the national economy, became clear, and as the president appeared outfoxed by his political nemesis Nancy Pelosi, the Democratic speaker of the House of Representatives.
But while Trump climbed down in agreeing to reopen government without first getting $5.7 billion in border wall funds, he still threatened to renew hostilities with a new shutdown, or a state of emergency, if there is no breakthrough on his pet project in the next three weeks.
"Over the next 21 days, I expect that both Democrats and Republicans will operate in good faith," said Trump as he announced he would reopen the government.
"If we don't get a fair deal from Congress, the government either shuts down on February 15th again, or I will use the powers afforded to me under the laws and Constitution of the United States to address this emergency," he warned.
"We really have no choice but to build a powerful wall or steel barrier."
S&P Global Ratings said late Friday that the shutdown cost "is likely worse than what we had previously expected."
Based on their analysis, "the US economy lost at least $6 billion ... larger than the $5.7 billion that the White House requested for the border wall," it said in a statement.
'Biggest wimp ever'
Trump triggered the shutdown in December to pressure congressional Democrats to give him funding for the border wall.
But the House Democrats calculated that voters would blame Trump for the ensuing chaos – and polls showed they were correct.
A wide range of federal workers, including the Secret Service and airport staff, have been left without salary for weeks, ramping up pressure on the president to reach a deal – even at the risk of angering his right-wing voter base.
Conservative commentator Ann Coulter wasted no time in lashing out.
"Good news for George Herbert Walker Bush: As of today, he is no longer the biggest wimp ever to serve as President of the United States," she tweeted, referring to the late president, a Republican moderate.
Good news for George Herbert Walker Bush: As of today, he is no longer the biggest wimp ever to serve as President of the United States.Ann Coulter (@AnnCoulter) 25 janvier 2019