Nancy Pelosi is officially House speaker. And in being sworn in, she’s making history for the second time.

Pelosi became the first female speaker in 2007 and served until 2011. Succeeded by two Republican men, she remains the only female speaker. But as she retakes the gavel Thursday, she is matching the legacy of renowned House Speaker Sam Rayburn of Texas by being the second speaker to reclaim the gavel after losing it in decades. At age 78, she’s becoming one of the oldest speakers elected.

The California lawmaker has skillfully navigated fraught political waters over the past few years to reclaim the gavel, and her return to power says something about her ability to run her caucus and her staying power during a time when speakers’ tenures are often limited.

“I think Nancy Pelosi is one of the smartest people in Congress,” Rep. Emanuel Cleaver (D-MO) told Vox last summer. “I think she’s almost like a shark; I don’t think she sleeps. She is as tough as they come.”

Even with her reputation for ruling her caucus, Pelosi faced mounting criticism from younger members after Democrats were out of power for eight years, starting after the 2010 midterms.

That criticism was compounded by grumblings within the caucus about a system that rewarded seniority and squandered new talent. After some critics in the Democratic caucus mounted a campaign to vote against Pelosi (albeit one that had no alternative to replace her), the Democratic leader agreed to limit her tenure to just four years, stepping down in 2022.

Pelosi is taking up the mantle of opposing Trump

Even as she shored up support within her own ranks, another thing has been working in Pelosi’s favor over the past few weeks — her ability to deal with President Donald Trump.

Pelosi is taking the reins during a time of political turmoil: a government shutdown that started before the holidays when Trump refused to sign a short-term spending bill over objections that it did not contain money for a border wall, his signature campaign promise.

With Senate Minority Leader Chuck Schumer, Pelosi went to the White House in December and told Trump something he isn’t used to hearing from congressional leaders: no.

Democratic leaders were adamant they would not fund Trump’s border wall. And from the start of the meeting, Pelosi branded any impending government shutdown as a “Trump shutdown.”

“I think the American people recognize that we must keep the government open, that a shutdown is not worth anything, and that you should not have a Trump shutdown,” she told the president.

By the end of the meeting, Pelosi and Schumer had pulled off a political feat — getting Trump to fully own a shutdown.

“You want to know something? I’ll take it,” Trump said. “Yes, if we don’t get what we want one way or the other, whether it’s through you, through military, through anything you want to call — I will shut down the government. I am proud to shut down the government. I will take the mantle.”

As Democrats head into the second week of a battle over government funding with the president, getting Trump to say on the record and in front of TV cameras that he was “proud” to shut down the government over the wall puts Democrats in a strong position to negotiate, no matter how much the president insists they are the ones to blame.

“The fact is, we did get him ... to fully own that the shutdown was his,” Pelosi told fellow Democrats when she returned to the Capitol after the meeting. “That was an accomplishment.”

Pelosi is an institutionalist — current and former aides say her loyalty lies completely in defending the legislative branch, and the House of Representatives in particular. While she respects the office of the president, it is clear she does not hold the same respect for its current occupant.

Trump presents a unique foil for Pelosi: prone to chaotic outbursts and completely off the cuff and unprepared, as opposed to her meticulous planning. There are areas where she wants to work with the president, including an infrastructure package and lowering prescription drugs. At the same time, she needs to oversee committee chairs conducting numerous investigations of the president and his administration, and protect the investigation of special counsel Robert Mueller.

The symbolic significance of Pelosi versus Trump cannot be lost here. The fact that she is an experienced woman going up against a president who has openly bragged about his lack of political experience and frequently demeaned women over social media is symbolic of a new divisive political era in Washington.

If 2018 was the year of the woman, 2019 will be the year of Pelosi versus the president.

Correction: An earlier headline of this story said Pelosi was the second person in history to reclaim the speaker’s gavel after losing it. She is the second person in nearly 60 years, after House Speaker Sam Rayburn, to hold the designation.