* Senate passes stopgap spending measure; House next
* Trump says shutdown could resume on Feb. 15
* He mulls emergency declaration to get wall built (Adds conservative criticism, Pelosi quote)
By Steve Holland and Richard Cowan
WASHINGTON, Jan 25 (Reuters) - President Donald Trump agreed under mounting pressure on Friday to end a 35-day-old partial U.S. government shutdown without getting the $5.7 billion he had demanded from Congress for a border wall, handing a political victory to Democrats.
The three-week spending deal reached with congressional leaders, quickly passed unanimously by the Republican-led Senate and heading to the Democratic-controlled House of Representatives, paves the way for tough talks with lawmakers about how to address security along the U.S.-Mexican border.
The Republican president's agreement to end the shuttering of about a quarter of the federal government without securing wall money - an astonishing retreat for a president who usually gives no ground - came three days after he had insisted "We will not Cave!"
But Trump vowed that the shutdown would resume on Feb. 15 if he is dissatisfied with the results of a bipartisan House-Senate conference committee's border security negotiations, or he would declare a national emergency to get the wall money.
Democrats remained unyielding in their opposition to a wall, one of his signature campaign promises that they call ineffective, costly and immoral. Trump has said it is needed to curb illegal immigration and drug trafficking.
With polls showing most Americans blamed him for the painful shutdown - the longest of its kind in U.S. history - Trump embraced a way out of the crisis that Democratic House Speaker Nancy Pelosi had been pushing for weeks. The shutdown, which pitted Pelosi against Trump - was her first test since assuming the post three weeks ago. She drew praise from fellow Democrats for what they said was an outmaneuvering of the president.
Asked by reporters if she could guarantee there will not be another government shutdown in three weeks, Pelosi said, "I can't assure the public about anything that the president will do, but I do have to say I'm optimistic."
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.
Speaking in the White House Rose Garden on a chilly, sunny winter day, Trump said he would act to ensure that federal workers get their back pay "very quickly, or as soon as possible."
Trump had previously demanded the inclusion of the money to help pay for a wall in any legislation to fund government agencies, but Democrats had blocked him.
An administration official, speaking on condition of anonymity, said that 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 re-open 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.
"We really have no choice but to build a powerful wall or steel barrier," Trump said. "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."
He previously has indicated he was considering an emergency declaration to circumvent congressional funding powers if lawmakers do not 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 wall-funding demand after being criticized by conservative commentators for being willing to sign legislation funding the government without securing wall money.
Conservative commentator Ann Coulter lashed out at Trump for capitulating on Friday, calling him on Twitter "the biggest wimp ever to serve as President of the United States."
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. Schumer said Democrats and Trump have "so many areas" on which they can agree on border security but not a wall.
"The walls we are building are not medieval walls," Trump said. "They are smart walls designed to meet the needs of front-line border agents and are operationally effective. 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."
"We do not need 2,000 miles (3,200 km) of concrete wall from sea to shining sea. We never did," Trump added. "We never proposed that. We never wanted that because we have barriers at the border where natural structures are as good as anything that we could build."
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 originally planned, and it is up to Pelosi to reschedule it.
(Reporting by Richard Cowan and Steve Holland in Washington; Additional reporting by Ginger Gibson, Lisa Lambert, Doina Chiacu and Jeff Mason; Writing by Will Dunham; Editing by Bill Trott and James Dalgleish)