It was the first battle in the war between Donald Trump and the newly empowered Speaker of the House, Nancy Pelosi. At stake were the fate of immigration reform, border security and government spending during the Trump presidency, and political clout with both the Republican and Democratic grassroots. And there was no doubt who won and who lost.

Speaking from the Rose Garden on Friday afternoon, Trump retreated from his demand for $5.7 billion for a border wall to reopen the government, endorsing a three-week stopgap measure that would immediately end the shutdown without any additional border security funding.

The retreat could have ripple effects far beyond the argument over a border wall, setting a template for future face-offs on everything from executive privilege to health care, immigration and infrastructure. Trump used every tactic he knows: a last-minute veto threat, aggressive tweets, a prime-time address from the Oval Office, a visit to the border, walking out of a high-stakes negotiation, and it didn’t work.

Trump couched his climbdown in the trappings of victory: A nationally broadcast speech from the Rose Garden, tough talk about border security, staffers clapping vigorously at the end.

“We have reached a deal to end the shutdown and reopen the federal government,” Trump said. “After 36 days of spirited debate and dialogue, I have seen and heard from enough Democrats and Republicans that they are willing to put partisanship aside — I think — and put the security of the American people first.”

Pelosi and Senate Democratic Leader Chuck Schumer were careful not to taunt the President after his speech, instead framing their remarks into a victory for the federal workers. “It’s sad … that it has taken this long to come to an obvious conclusion,” said Pelosi. But it was clear to both Republicans and Democrats that, in Trump’s first big face-off against Democrats, the President had lost by every metric he himself set.

Before the shutdown, Trump said he would proudly own it; he ended it blaming Democrats. He argued that the public was on his side; polls showed a majority of Americans opposed the wall and the shutdown. He embraced a fight over the State of the Union; Pelosi won the argument. He argued Republicans were sticking together; a half-dozen GOP senators defected on a vote Thursday. He repeatedly vowed not to cave on wall funding; in the end, he did just that.

Outside the carefully managed Rose Garden appearance, even his supporters saw the reality of the situation.

“Trump is the Babe Ruth of our era: he doesn’t practice and takes big bold swings,” said Republican donor Dan Eberhart. “Sometimes he hits dramatic game-winning home runs. Shutting down the government over the border wall is a game-ending strikeout for his team.”

Democrats, it goes without saying, agreed.

“This is pretty close to an unconditional surrender,” said one House Democratic aide.

President Trump returns to the Oval Office after his remarks on the shutdown on Jan. 25, 2019. David Butow—Redux for TIME

The deal includes a plan for the House and Senate to go to conference to debate border security measures. Trump said a “bipartisan conference committee of House and Senate lawmakers and leaders” will “put together a homeland security package for me to shortly sign into law.” He spent the bulk of his announcement talking about the danger at the border, the necessity of a wall and claiming that he has found bipartisan support for one.

But he also offered a threat to invoke controversial emergency powers to build the wall, something he had repeatedly mulled during the shutdown. “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 the Constitution of the United States to address this emergency,” he said.

Apart from the broader public, the fight also hurt Trump among his base and on his signature issues.

According to a Fox News poll conducted Jan. 20-22, more voters were more concerned about the shutdown than about border security: 75% said they considered the shutdown an emergency or major problem, while 59% said the same about the situation at the border. The same poll found Trump’s approval at or near record lows with key parts of his base. Over the course of a month during the shutdown, the Fox News poll found Trump’s approval rating had dropped 10 points among Republican women (to 83%) and suburban men (to 43%) and dropped 7 points among white evangelical Christians (to 71%).

He’s even been hurt on border security, the very issue he started the shutdown over in the first place: a Quinnipiac poll conducted Jan. 9-13 found that by a margin of 49-44%, American voters trust Democrats in Congress more than Trump on border security.

While the shutdown hurt Trump with voters, cracking his base just as the 2020 presidential campaign begins, it also weakened his negotiating position as he heads into two more years of butting heads with Pelosi. Democratic committee chairs in the House have already outlined an aggressive approach to investigating the president on everything from his old business deals to the way his Administration granted security clearances, and as Trump faces a potential onslaught of document requests, subpoenas, hearings and possibly even impeachment proceedings, he’s leaving this situation with much less leverage. And he has exposed the divisions in his own party, both between him and Republican congressional leaders and with the GOP caucus.

Read More: House Democrats Get Ready to Fight Trump. And Each Other

On the other side, as much as Trump was hobbled by this fight, Pelosi was strengthened by it. Before she regained the Speaker’s gavel, she faced internal dissent within her caucus from people who thought she should not return to the position because it was time for new leadership. Her allies, though, argued that she had the right mix of experience and judgement, and the results of this clash largely proved them right.

Trump never had the full blessing from Republican leadership in the Senate to proceed with this shutdown. For the most part, they seemed largely baffled by what the President was trying to accomplish with it. After unanimously passing a temporary spending bill through the Senate that would have averted the shutdown this past December, only to see the President flip his position, Senate Majority Leader Mitch McConnell relegated himself to the sidelines, stipulating that the onus was on Democrats and the White House to reach a deal.

The breakthrough happened Thursday, day 34 of the shutdown, after the Senate voted down two procedural measures that would have paved a path to ending the shutdown. But the measure driven by the President drew less support than the one proposed by the Democrats, which, much like what Trump announced Friday, temporarily reopened the government with no wall funding. Following these votes, McConnell summoned Schumer to his office, where, according to a senior Senate Democratic aide, he offered a short term funding bill in exchange for a down payment on the wall. Schumer said the Democrats would not support any wall funding, and pitched a plan that largely aligned with the one the President announced Friday. McConnell said he would take the proposal to the White House.

“The only way the federal government workers are going to have security and certainty beyond the next three weeks,” McConnell said after Trump’s announcement, “Is if Democrats will stop playing partisan games and get serious about negotiating with the president on a long term compromise.”

While it was clear something was afoot before Trump’s announcement, McConnell and Schumer remained mum, only telling reporters that they were “talking.” But House Democrats postponed a press conference, which was originally supposed to be held Friday morning, to unveil their own plans for border security spending.

Since December, Trump has been insisting on a government funding package that includes more than $5 billion for a border wall. Democrats have refused to budge above $1.6 billion and insisted on reopening the government before wrangling over border security funding. The Democrats largely got their wish. Friday’s proposal was really what they had been pushing for all along — reopening the government, and debating border security later.

The president’s core team working on this issue has been hoping that ending the shutdown would be just the beginning of tackling America’s immigration system. “The hope is when we get through this situation,” Jared Kushner, Trump’s son-in-law and senior adviser, told reporters on Jan. 19, “that this could be a step towards broader immigration reform.”

“Many disagree, but I really feel that working with Democrats and Republicans we can make a truly great and secure deal happen for everyone,” Trump said Friday. “Walls should not be controversial.”

But after Friday’s concession, Democrats may have little incentive to play along.

Get our Politics Newsletter. The headlines out of Washington never seem to slow. Subscribe to The D.C. Brief to make sense of what matters most. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

Write to Alana Abramson at Alana.Abramson@time.com and Tessa Berenson at tessa.berenson@time.com.