WASHINGTON — President Trump agreed on Friday to reopen the federal government for three weeks while negotiations continued over how to secure the nation’s southwestern border, backing down after a monthlong standoff failed to force Democrats to give him billions of dollars for his long-promised wall.

The president’s concession paved the way for the House and the Senate to both pass a stopgap spending bill by voice vote. Mr. Trump signed it on Friday night, restoring normal operations at a series of federal agencies until Feb. 15 and opening the way to paying the 800,000 federal workers who have been furloughed or forced to work without pay for 35 days.

The plan includes none of the money for the wall that Mr. Trump had demanded and was essentially the same approach that he rejected at the end of December and that Democrats have advocated since, meaning he won nothing concrete during the impasse.

Mr. Trump presented the agreement with congressional leaders as a victory anyway, and indicated in a speech in the Rose Garden that his cease-fire may only be temporary: If Republicans and Democrats cannot reach agreement on wall money by the February deadline, he said that he was ready to renew the confrontation or declare a national emergency to bypass Congress altogether.

According to an analysis from Standard & Poor’s, the ratings agency, the United States economy lost at least $6 billion in the five weeks the government was partly shuttered — more than the $5.7 billion that Mr. Trump had requested to build a steel or concrete barrier at the border.

Mr. Trump offered no explanation for his surrender, nor did he acknowledge that it was one. On Twitter on Friday night, he said: “This was in no way a concession. It was taking care of millions of people who were getting badly hurt by the Shutdown with the understanding that in 21 days, if no deal is done, it’s off to the races!”

During the president’s speech earlier in the day, cabinet officials and White House aides lined the sides of the Rose Garden and applauded him. Mr. Trump began his remarks as if he had actually emerged victorious, saying that he was “very proud to announce” what he called “a deal to end the shutdown and reopen the federal government.”

Few lawmakers even in the president’s own party saw it that way.

“I hail from a state that is very supportive of the president and border security with barriers, so that is a consideration for me, but there are a lot of other strategies we could employ that would work better” than a shutdown, said Senator Shelley Moore Capito, Republican of West Virginia.

With polls showing the president enduring most of the blame by the public, Republicans led by Senator Mitch McConnell of Kentucky, the majority leader, pressured Mr. Trump to agree to the temporary truce. Over the next three weeks, a House-Senate conference committee representing both parties will negotiate a border security plan, but if it fails to reach a consensus, government agencies could close again.

Mr. McConnell and Mr. Schumer huddled on Thursday night after the failed votes to discuss a path forward. Mr. Schumer rejected the idea of offering a down payment for the wall to reopen the government and pitched Mr. McConnell on what ultimately became the agreement with Mr. Trump, according to a senior Democratic aide.

Mr. McConnell, who viewed the shutdown as unnecessary from the start, found Mr. Trump eager to end the impasse, and in a series of calls, they ironed out the details. To the Republican leader, it was a way to ease much of the pressure on federal workers and get the Senate back to work.

As late as early Friday morning, Mr. Trump appeared intent on declaring a national emergency at the border alongside the agreement to reopen the government, but Mr. McConnell and White House officials encouraged him to drop the idea, according to people familiar with the discussions who were not authorized to discuss them.

Republican leaders tried to rally their members during a closed policy luncheon before Thursday’s votes. But even as Republicans prepared to support Mr. Trump’s plan, the signs of mounting frustration after weeks of inaction were evident.

Republican senators rose one by one to voice concerns about the effect on federal workers and the lack of forward momentum in an impasse that felt unbearable. They swore they would never stand by another government shutdown.

“We’ve already lost,” lamented Senator Johnny Isakson, Republican of Georgia, according to people familiar with the remarks. “It’s a matter of the extent we want to keep losing.”