The Democrats have won the House, and Republicans will have to hand over the speaker’s gavel in January. But it’s not totally clear whom that gavel will go to.

The long-running drama over the fate of House Democratic Leader Nancy Pelosi is entering a new phase. It has been clear for months that Pelosi might not have enough Democrats behind her to become speaker. Some incumbent House Democrats oppose the California Democrat because they believe it’s time for a new figure to lead the party, which Pelosi has done since 2003. And dozens of Democratic candidates, facing a barrage of attacks from Republicans linking them to Pelosi, pledged during their campaigns not to support her in a speaker vote. Of course, many of Pelosi’s critics were running in very red districts — so they lost.

But Pelosi still has some work to do if she wants a second tenure as House speaker. With almost all the 435 House races decided, we did a whip count of the newly elected or re-elected Democrats. Here’s what we found: Pelosi does not appear to have 218 votes to become speaker, unless some Democrats backtrack from previous comments suggesting that they will not support her.

Before the election, NBC News and reporter Ally Mutnick of the National Journal put together lists of Democratic candidates who said they would not support Pelosi either for Democratic leader or for speaker if the Democrats took control of the House. Combining their research with ours, we identified at least 63 anti-Pelosi candidates — 21 of whom won their elections.

Democratic-members elect who might not support Pelosi As of 4:00 p.m. on Nov. 8 Candidate District Incumbent? Vote Margin Rashida Tlaib MI-13 D+73.2 Brian Higgins NY-26 ✓ D+47.1 Bill Pascrell NJ-9 ✓ D+40.9 Jim Cooper TN-5 ✓ D+35.7 Seth Moulton MA-6 ✓ D+34.6 Linda Sánchez CA-38 ✓ D+33.7 Ed Perlmutter CO-7 ✓ D+24.1 Kathleen Rice NY-4 ✓ D+22.1 Tim Ryan OH-13 ✓ D+21.6 Filemón Vela TX-34 ✓ D+19.5 Mikie Sherrill NJ-11 D+13.3 Kurt Schrader OR-5 ✓ D+13.1 Conor Lamb PA-17 ✓ D+12.4 Jahana Hayes CT-5 D+11.7 Jason Crow CO-6 D+10.0 Haley Stevens MI-11 D+6.7 Jeff Van Drew NJ-2 D+6.3 Max Rose NY-11 D+6.0 Elissa Slotkin MI-8 D+3.8 Abigail Spanberger VA-7 D+1.9 Joe Cunningham SC-1 D+1.4 Vote margins may change as results are tallied. Six candidates who said they would not vote for Pelosi are in races that are still too close to call, so this list may grow. Sources: ABC News, NBC News, Ally Mutnick, other media reports

With a handful of races still unresolved, Democrats have won 224 seats — that number is likely to increase, but it’s hard to see them winning more than 235. Even at that high mark, Pelosi would be four votes short of 218 if the 21 Democrats followed through on their pledge not to support her. The anti-Pelosi faction includes 11 incumbents, some of whom have long been critical of her, like New York’s Kathleen Rice and Ohio’s Tim Ryan. The other 10 will be joining the House with the new class of members in January.

Of course, Pelosi could still become speaker even if she is a few votes short at the moment. And she’s probably the favorite. How would she get there? There are at least three pathways.

The most direct way for Pelosi to become speaker is that at least a few of these anti-Pelosi members backtrack on their campaign pledges. Could that happen? Maybe. Nine of the 21 anti-Pelosi candidates won by more than 20 percentage points. It’s unlikely that voters in fairly liberal-leaning areas will vote out their members in November 2020 over a pro-Pelosi vote in January 2019. Also, it’s not clear there is an obvious person with broad support to replace her, so other House Democrats might convince the anti-Pelosi wing that there is no real alternative.

And Pelosi could try to persuade her opponents to change their positions by either pledging to serve as speaker only through 2020 or picking a No. 2 whom the anti-Pelosi bloc likes.

This is easy to describe but probably difficult to execute. Many new members have no particular loyalty to Pelosi — and some incumbents, like Ryan, have openly frosty relationships with her. The anti-Pelosi faction could try to block her from becoming the Democrats’ designated candidate for speaker or just refuse to back her in January, forcing the party to pick someone else.

There’s a second, more complicated way for Pelosi to become speaker — her critics voting “present” rather than “no” in the House speaker election. Let’s walk through that, because it’s a bit complicated.

The first step in the speaker selection process is that each party has an internal vote to determine its candidate. This vote takes place behind closed doors, usually in late November or early December. (Newly elected members travel to Washington to participate in this process.) Then there is a formal vote in the House in January that typically pits a Democratic candidate against a Republican one. The winner is the new speaker.

Assuming for now that Pelosi makes it through the private vote to the January vote in the House, she will need a majority of those choosing between the two candidates (California’s Kevin McCarthy is the favorite to be the GOP choice). But that doesn’t mean she would need 218 votes (an outright majority of the House). If members vote “present,” it brings the threshold for a majority down.

So let’s say that after the election results are finalized, the House is made up of 230 Democrats and 205 Republicans and that the number of anti-Pelosi Democrats stays at 21. If all 21 vote “present” and the rest of the Democrats back her, she will win the speakership 209-205. But if Democrats don’t make it to 230 and end up with 228 seats or fewer, Pelosi won’t have the votes to win, even if the Democratic faction against her votes “present.” In that case, she’d need some Democrats to backtrack on their pledges to oppose her.

A third way for Pelosi to become speaker is for the anti-Pelosi Democrats to vote against her in the private party vote but for her in the floor vote. Since many of the candidates simply said they wouldn’t vote for Pelosi as “party leader,” they could claim to be keeping their campaign promise while still allowing Pelosi to become speaker of the whole House. After all, the speaker election would probably only have two viable candidates — Pelosi and McCarthy (or another Republican).

As you can see, there’s still a good deal of uncertainty about how the speaker vote will play out.

Let’s finish by saying clearly: Lots of gossipy stories about internal Washington machinations ultimately don’t matter. This one does. With Trump in the White House and Mitch McConnell in charge of an enlarged Republican majority in the Senate, the Democratic speaker will have a huge role in determining exactly when and how the party tries to constrain Trump, as well as how or if House Democrats try to work with him on major issues. The Democrats are also trying to come up with a strategy that will increase the chances that the party’s 2020 presidential candidate will win. And the Democrats in the House will have a fairly diverse group both demographically and ideologically. So the speaker has to satisfy not only liberals like Alexandria Ocasio-Cortez of New York but also moderates like Conor Lamb of Pennsylvania. None of this will be easy.