Donald Trump has agreed to a deal to reopen the US government for three weeks, backing down from demanding that Congress give him money for his border wall before federal agencies get back to work.

Submitting to mounting pressure amid growing disruption, Mr Trump said he would sign legislation funding closed agencies until February 15 and try again to persuade lawmakers to finance his long-sought wall.

The deal he reached with congressional leaders contains no new money for the wall but ends the longest shutdown in US history.

First the Senate, then the House of Representatives swiftly and unanimously approved the deal.

The president signed the bill late on Friday and his administration asked federal department heads to reopen offices in a “prompt and orderly manner”.

Mr Trump’s retreat came in the 35th day of the partial shutdown as intensifying delays at the nation’s airports and another missed payday for hundreds of thousands of federal workers brought new urgency to efforts to resolve the standoff.

The shutdown was ending as Democratic leaders had insisted it must — reopen the government first, then talk border security.

“The president thought he could crack Democrats, and he didn’t, and I hope it’s a lesson for him,” said the Senate Democratic leader, Chuck Schumer.

House Speaker Nancy Pelosi said of her members: “Our unity is our power. And that is what maybe the president underestimated.”

Mr Trump still made the case for a border wall and maintained he might again shut down the government over it.

Yet, as negotiations restart, Mr Trump enters them from a weakened position.

A strong majority of Americans blamed him for the standoff and rejected his arguments for a border wall, recent polls show.

“If we don’t get a fair deal from Congress, the government will either shut down on February 15, again, or I will use the powers afforded to me under the laws and Constitution of the United States to address this emergency,” Mr Trump said.

The president has said he could declare a national emergency to fund the border wall unilaterally if Congress does not provide the money.

Such a move would almost certainly face legal hurdles.

As part of the deal with congressional leaders, a bipartisan committee of House and Senate lawmakers was being formed to consider border spending as part of the legislative process in the weeks ahead.

“They are willing to put partisanship aside, I think, and put the security of the American people first,” Mr Trump said.

He asserted that a “barrier or walls will be an important part of the solution”.

The deal includes back pay for some 800,000 federal workers who have gone without paychecks.

The Trump administration promises to pay them as soon as possible.

Also expected is a new date for the president to deliver his State of the Union address, postponed during the shutdown.

But it will not be January 29 as once planned, according to a person familiar with the planning.