The shutdown is over. For three weeks, anyway.

President Donald Trump told reporters Friday that he had reached a deal with congressional leaders to reopen the government until Feb. 15, giving relief to federal workers and the American people they serve as well as handing a major political victory to emboldened Democrats.

Trump, who over the course of the record 35-day partial government shutdown had called Democratic leaders names, offered them candy, stormed out of a White House meeting and presented a counteroffer that was quickly rejected, got virtually nothing out of the deal reached Friday. The measure reopens the government, provides for quick-as-possible back pay for 800,000 federal workers who were furloughed or required to work without pay and allows for further negotiations on border security.

But it does not give Trump a penny for the border wall the president had insisted was necessary for both national security and to make the government fully operational again. He did extract a promise that Congress go directly to a bipartisan, bicameral negotiation on border security, offering the chance of getting some funding for a wall.

"Walls work. They do work. No matter where you go, they work," Trump said in a Rose Garden appearance. He did not say what made him give in – even for three weeks – but warned he might try the same tactic again.

"We really have no choice but to build a powerful wall or a steel barrier. If we don't get a fair deal from Congress, the government will either shut down on Feb. 15 again, or I will use the powers afforded to me under the laws and Constitution of the United States to address this emergency," the president said.

Trump was referring to an earlier threat to declare the border a "national emergency" and use federal funds to build a wall without congressional approval. Such an action would certainly end up in the courts, leading to a lengthy legal battle.

The deal represents a huge win for newly installed House Speaker Nancy Pelosi of California, who held firm and insisted there be no money for a border wall in any agreement to reopen the government. Pelosi has called the wall "immoral," sending a signal that America is rejecting immigrants and refugees. But the other issue was one of precedent: Democrats did not want Trump to learn that he can get whatever agenda item he wants by threatening to shut down the government.

And Trump, whose experience is in making business deals, found that negotiating with a divided Congress is trickier. Lawmakers may respect the president – and in the case of Republicans, support his goals – but they ultimately answer to constituents. And Americans were making it clear they were unhappy with the shutdown.

"Public sentiment is everything. It can accomplish anything," Pelosi told reporters as Congress prepared to pass the deal. "It's sad that it took this long to come to an obvious solution." Asked if she thought Trump was trying to weaken her by using the shutdown as a tool, she said, "I don't see this as a power play. Let's go forward, get this done. … I don't want to make any characterization of the president's motivation. You'll have to ask him."

The Photos You Should See - Jan. 2019 View All 48 Images

She said she will now be able to discuss with the White House a date for the State of the Union, which she had refused to schedule as long as a shutdown persisted.

For Trump, the border wall became a symbol not only of his allegiance to his base, who chanted "build the wall!" during his rallies, but to his own self-vaunted ability to make deals and get the better end of them. As the country grew restless and then angry with the protracted shutdown, the White House floated ideas of wall funding that could be called a "barrier" or of a "down-payment" on a wall instead of the entire $5.7 billion Trump sought to start construction.

Trump also offered to reinstate two immigration-related items he had revoked earlier in his presidency – temporary protection for young immigrants whose parents brought them here illegally when they were young and people here on "temporary protected status" because of upheaval back in their home countries .

Democrats quickly dismissed that offer as "hostage-taking" and were further angered when they learned the details of the president's proposal, which would have made it harder for people to apply for asylum and impose higher fees many refuge seekers could not pay.

The standoff had both parties largely united, and the two sides essentially waited it out while the shutdown – damaging to both the national economy and individuals' personal finances – played out in the court of public opinion.

The Democrats won that fight, though it was Americans who receive government paychecks or services who ended up being the front-line soldiers getting hurt in the battle.

Some 380,000 federal workers were sent home without pay, while another 420,000 employees – some making salaries of $30,000-$40,000 as Transportation Security Administration agents or federal prison guards – were required to come to work despite not being paid. Many complained about the financial hardship, being forced to visit homeless shelters or food pantries to feed their families.

Others called in to say they could not make it to work, since they could not afford the gas, tolls and child care expenses needed to get there. Delayed assistance was affecting farmers, public housing residents and landlords, and air travelers who were funding longer lines at airport security because of increased absences by TSA agents.

The situation became more dire Friday, as it was reported that thousands of IRS agents ordered back to work without pay were not coming in to process returns. Perhaps more dramatically, plane travel was slowed at New York's LaGuardia Airport because of air-traffic controller staffing shortages.

Meanwhile, polling was showing that Trump's approval rating is very low and that the public was overwhelmingly blaming him and Republicans for the shutdown. A Washington Post-ABC poll released hours before Trump spoke in the Rose Garden showed that 58 percent of Americans surveyed disapprove of the president, 53 percent blamed him and the GOP for the shutdown – opposed to the 34 percent who blame Pelosi and Democrats – and 1 in 5 Americans say they have been personally inconvenienced by the shutdown.

Immigrant advocates hailed the deal and revelled in what they saw as Trump's defeat.

"Isolated, defeated and desperate, President Trump flew the white flag today. He has finally relented, agreeing to reopen the government he closed and to stop the suffering he caused," Frank Sharry, executive director of America's Voice, said in a statement. To Congress, Sharry said, "it's time to turn your attention from saving face for one man to keeping the government open for all."

Meanwhile, Trump may well endure a backlash from his base. In the week before Christmas, Trump had appeared ready to approve legislation to keep the government running while lawmakers continued talking about border security. After criticism from conservatives – including commentator Ann Coulter, who said such a move would make Trump's a "joke presidency" – Trump balked, and the government shut down.