Flashback 40 days and Nancy Pelosi’s return to the speakership was a hard-won prize marred by Democratic grumbling.

After the midterm elections, 15 House Democrats signed a letter urging their colleagues not to support Pelosi for speaker: “We promised to change the status quo and we intend to deliver on that promise.” To recapture the gavel, Pelosi had to promise to be a “transitional” speaker, and many Democrats felt she only regained the role because there were no compelling alternatives.

It’s not that House Democrats dismissed Pelosi’s skills as a legislator, but what they needed was an answer to President Trump, and that didn’t seem like a role Pelosi was suited to play.

But in recent weeks, Speaker Pelosi proved a powerful foil to Trump, politically humiliating him in a way no other public figure has. Today, Trump buckled, agreeing to reopen the government in exchange for absolutely nothing, just days after he agreed to Pelosi’s demand to postpone the State of the Union.

Pelosi’s success turned on a few key factors. The first is the legislative and coalitional skill that even her skeptics always admitted she possessed. Pelosi held her caucus together easily and calmly, creating a united front that offered Trump few avenues of egress. When the president tried to invite moderate Democrats to negotiate without Pelosi present, they simply stood him up. With her caucus firm, she was able to pick a position and hold to it.

“We’re grateful to Democrats on both sides of the Capitol for their unity. That was very, very important in these discussions,” Pelosi noted in her victory lap press conference Friday afternoon.

Second, Pelosi correctly read Trump’s personality and had the steel to act on that read. For years now, members of Congress have divided on whether Trump is strong or weak, whether his political success shows an intuitive tactical genius that needs to be respected or a hollow showman who connects to conservatives but is easily flummoxed.

Pelosi has long held that Trump is weak, easily confused, and easily baited. That informed her strategy. Along with Senate Minority Leader Chuck Schumer, she baited Trump into saying, while the cameras were rolling, “I will shut down the government. I am proud to shut down the government. I will take the mantle.” In interviews and meetings, she tweaked the president, calling the crisis “the Trump shutdown” to Trump’s face and suggesting the billionaire thought furloughed workers “could just ask their father for more money.” She was betting that Trump would overreact rather than turn her into the aggressor, and he did.

Pelosi also drew a hard line on the wall, and then made an even higher-risk gamble in postponing the State of the Union, betting all the while that Trump would blink. Again, she was right.

Third, Pelosi had the crucial assistance of Trump himself. He forced a shutdown his own party tried to avoid, he publicly took ownership of that shutdown, and he held to a position that was unpopular at the start and grew more toxic by the day. The core structure of this conflict was always that the public didn’t want a government shutdown, Democrats didn’t want a government shutdown, and Trump was forcing a government shutdown. Pelosi would’ve had to make some terrible tactical errors to lose from a position that strong, and she didn’t.

Now, just days after agreeing to postpone the State of the Union at Pelosi’s insistence, Trump has agreed to reopen the government without any funding for his wall. Pelosi has proved what many didn’t believe about Trump: that he is subject to the normal laws of political gravity, and that for all his bluster, he is no more capable of sustaining an unsustainable position than any other politician.

During the shutdown, Pelosi’s chief of staff from 2011 to 2017, Nadeam Elshami, put it this way to my colleague Ella Nilsen: “[Trump] hasn’t experienced Nancy Pelosi in the majority, let me just say that.”

Now, he has.

Trump’s decision to force this fight has both delivered him a loss and reset Washington’s expectations going forward. Pelosi is now the clear leader of the Democratic opposition, and she has shown herself more than Trump’s equal in a legislative showdown. She has enhanced her standing in her caucus, and he has diminished his standing inside his own. You don’t hear many House Democrats these days grumbling about Pelosi’s leadership. But you hear plenty of Republicans lamenting Trump’s.