U.S. President Donald Trump agreed under mounting pressure on Friday to end a 35-day-old partial government shutdown without getting the money he had demanded from Congress for a border wall.

A three-week stopgap spending plan, passed unanimously by both the Senate and to the House of Representatives, now sets up tough talks with lawmakers about how to address security along the U.S.-Mexican border, with Democrats appearing unyielding in their opposition to Trump's wall.

With polls showing most Americans blamed Trump for the painful shutdown — the longest of its kind in U.S. history — the president embraced a way out of the crisis that Democratic House Speaker Nancy Pelosi had been pushing for weeks.

But the Republican president vowed the shutdown would resume on Feb. 15 if he is dissatisfied with the results of the border security talks, or he would declare a national emergency to get the wall money.

With the effects of the shutdown spreading, Trump signed the stopgap spending measure on Friday, after it passed unanimously in both the Republican-led Senate and the Democratic-led House.

The shutdown, which pitted Pelosi against Trump, was her first test since assuming the Speaker post three weeks ago, and she drew praise from fellow Democrats for what they said was an outmanoeuvring of the president.

After Trump announced the agreement, top Senate Democrat Chuck Schumer said he hoped the experience would be a "lesson learned" for Trump and his party that it is self-defeating to shut down the government over policy disputes.

"I am very proud to announce today that we have reached a deal to end the shutdown and reopen the federal government," Trump — who days earlier had insisted "We will not Cave!" — said in the White House Rose Garden.

A lapse in funding shuttered about a quarter of federal agencies, with about 800,000 workers either furloughed or required to work without pay. Many employees as well as contractors were turning to unemployment assistance, food banks and other support. Others began seeking new jobs.

House Speaker Nancy Pelosi, left, and Senate minority leader Chuck Schumer are seen at a news conference on Capitol Hill on Friday. Pelosi drew praise from fellow Democrats for what they said was an outmanoeuvring of the president. (Andrew Harnik/Associated Press)

Trump said he would act to ensure federal workers get their back pay "as soon as possible."

Trump had previously demanded the inclusion of $5.7 billion US to help pay for a border wall — one of his signature campaign promises — in any legislation to fund government agencies, but Democrats had blocked him.

An administration official, speaking on condition of anonymity, said stories of law enforcement officials not being able to do their jobs at full capacity helped convince Trump to agree to a short-term solution to reopen the government. The official said the White House ultimately would accept a deal with lawmakers if it includes wall funding, even if it is less than $5.7 billion.

The agreement requires passage in the House and Senate and Trump's signature. Trump said a bipartisan congressional conference committee will meet to come up with a plan for border security. Schumer said Democrats and Trump have "so many areas" on which they can agree on border security but not a wall.

Trump mulls using emergency powers

Trump says the U.S. has no choice but to build a "powerful wall or steel barrier" along the border with Mexico.

"If we don't get a fair deal from Congress, the government will either shut down on Feb. 15 — again — or I would use the powers afforded to me under the laws and the Constitution of the United States to address this emergency."

Port of Seattle workers carry items donated to federal workers at Seattle-Tacoma International Airport on Friday. With about 800,000 workers either furloughed or required to work without pay, many federal employees as well as contractors were turning to unemployment assistance, food banks and other support. (Ted S. Warren/Associated Press)

He had previously indicated he was considering an emergency declaration to circumvent congressional funding powers if lawmakers refused to fund his wall, an action that almost certainly would be swiftly challenged by Democrats as exceeding his authority under the U.S. Constitution.

Trump triggered the shutdown, which began on Dec. 22, with his hard-line wall-funding demand. The Democrats rejected it on the grounds that a wall would be costly, ineffective and immoral. Trump has said it is necessary to curb illegal immigration and drug trafficking.

"The walls we are building are not medieval walls. They are smart walls designed to meet the needs of front-line border agents and are operationally effective," he said. "These barriers are made of steel, have see-through visibility, which is very important, and are equipped with sensors, monitors and cutting-edge technology, including state-of-the-art drones."

Members of unions, federal workers and contractors hold a rally at Airport Circle in Egg Harbor Township, N.J., on Friday. Some federal agencies have reported much higher absence rates among workers as they face an indefinite wait for their next paychecks. (Edward Lea/The Press of Atlantic City via AP)

Pelosi said she would discuss with Trump "a mutually agreed date" for his annual state of the union address, which she had effectively forced him to postpone amid the shutdown showdown. A senior White House official said the speech will not be on Tuesday, as it had originally been planned, and that it is up to Pelosi to reschedule it.

The temporary funding bill would extend agency funding at the last fiscal year's levels and would include some money for border security — but not a wall, which Trump had initially said would be paid for by Mexico.

In one of the many effects of the shutdown, hundreds of flights were grounded or delayed at airports in the New York area and Philadelphia on Friday as more air-traffic controllers called in sick. Some federal agencies have reported much higher absence rates among workers as they face an indefinite wait for their next paycheques.