A few years ago, the Brookings Institution scholar Thomas Mann said that during her time running the House of Representatives, Nancy Pelosi had proved to be the “strongest and most effective speaker of modern times.” To understand why, just look at the way Pelosi has engineered her likely return to the job over the past week.

In August, NBC asked Democrats running for the House whether they supported making Pelosi speaker again. A whopping 58 refused to endorse her. Even more ominous, the abstainers hailed from every wing of the party. They included many of the moderate Democrats with the best chances of winning in Republican-leaning districts: Conor Lamb in Pennsylvania; Mikie Sherrill in New Jersey; Jared Golden in Maine; Gil Cisneros in Orange County, California; and Max Rose in Staten Island, New York. But some of the party’s rising progressive stars—Ayanna Pressley, Rashida Tlaib, and Alexandria Ocasio-Cortez—snubbed Pelosi, too. It appeared to be one of the few points of consensus among Democrats of all stripes. “There is widespread agreement,” Representative John Yarmuth of Kentucky told Vox in July, “that we need a rejuvenation of leadership.”

What Pelosi realized, however, was that the very breadth of the skepticism toward her afforded her an opportunity. She didn’t have to convince either moderates or progressives that she was their ideal choice. She only had to convince each group of would-be rebels that the other was worse.

The first move in that strategy occurred last Thursday night when Pelosi met with Representative Pramila Jayapal, the incoming co-chair of the House Progressive Caucus. Jayapal had every reason to oppose Pelosi’s return to the speakership. The Seattle congresswoman is working on legislation to abolish Immigration and Customs Enforcement (ice); she has already voted to impeach Trump. Pelosi has mocked both causes on the record. “I have those who want to be for impeachment and for abolishing ice,” she told Robert Draper of The New York Times Magazine this week. “Two really winning issues for us, right? In the districts we have to win? I don’t even think they’re the right thing to do.”

But Jayapal left Pelosi’s office with a commitment that Progressive Caucus members would enjoy better committee assignments and more say over legislation. And in return, she not only announced her support for Pelosi as speaker, but, according to Politico, also called the influential activist groups MoveOn and Indivisible, which quickly declared their support for Pelosi, too.

How did these progressive hard-liners justify supporting Pelosi, whose history of ideological compromise and big-donor fund-raising represents much of what they despise about the modern Democratic Party? They said her opponents were worse. Jayapal told Politico that the “drive” by party moderates to depose Pelosi “is not going to take us in the direction that we should go. It’s going to be the opposite of what the election really told us, which is a much more diverse, progressive, bold agenda.” MoveOn tweeted that “Dems must reject attempts to defeat” Pelosi “and move caucus to the right.” Indivisible declared, “We shouldn’t let a small group of white, moderate men sabotage her.” On Monday, Ocasio-Cortez—who had refrained from endorsing Pelosi during the campaign—justified her support in identical terms. “Out of the field, I would say that she is the most progressive candidate,” Ocasio-Cortez announced on Instagram. “All of the rebellion for the speakership are challenges to her right.”

It was a self-fulfilling prophecy. After the 2016 elections, 63 House Democrats had voted to dump Pelosi as speaker. But on Monday, after the Progressive Caucus’s endorsement of Pelosi, only 16 (11 sitting members and five who have just been elected) signed an open letter demanding “new leadership.” As damaging as the small number was the composition. Thirteen of the 16 were white males. Of the 11 sitting members, according to govtrack.us, 10 had a more conservative voting record than the average House Democrat in 2017. Many had a history of opposing abortion or gun control.

The moderate rebels grasped this liability. They knew that, on their own, they could not win over a caucus composed largely of progressives, women, and people of color. By Monday, their hopes for ideological jujitsu rested in large measure on Marcia Fudge, an African American representative from Cleveland who had called for “acknowledging the fact that the Democratic Party is becoming more young, more black, and more brown and letting that be reflected in our leadership.” Fudge had also slammed Pelosi as “a very wealthy person” who “raises a lot of money from a lot of other wealthy people.” Two of the ringleaders of the moderate revolt, Tim Ryan and Seth Moulton, were publicly boosting Fudge, who last week told The Washington Post, “I’ve been overwhelmed by the amount of support I’ve received.”

But that supposedly overwhelming support didn’t include a public endorsement by a single member of Fudge’s own Congressional Black Caucus. And on Tuesday night, after being named to lead a new House subcommittee to combat voter suppression, Fudge threw her support behind Pelosi, denying moderates the progressive fig leaf they desperately needed. Soon after Fudge’s announcement, The Washington Post’s Dave Weigel tweeted, “A quick update on Seth Moulton’s quest to block Pelosi from the speaker’s gavel.” Below it was a gif of a cartoon character who steps on a succession of different rakes, each of which pops up and slams him in the face.

This is why Pelosi deserves to be speaker again: She possesses the skills that the job requires. She may be a lackluster orator who, according to polls, lacks widespread support even among grassroots Democrats. But when it comes to outmaneuvering her opponents inside the Capitol’s marble walls, no one in her party even comes close.