Democrats won a House majority in the midterm elections — but a majority narrow enough that top party leader Nancy Pelosi’s path to becoming speaker is in question, heralding weeks of intense jockeying to hash out the party leadership.

Pelosi made clear in the hours leading up to her party’s victory she has no intention of stepping aside after bringing Democrats back to power after eight years in the minority. “Not that any of us is indispensable, but I think I’m really the best person for the job,” she said on PBS’s “NewsHour.”

But the raw arithmetic of the incoming Democratic majority remains an obstacle to Pelosi taking the speaker’s gavel. According to House results as of 9 a.m. Wednesday, Democrats had secured at least a five-seat majority, while on track to net an additional six seats from Republicans in still-uncalled races.

A margin of 11 seats or thereabouts could give a small group of Democrats leverage to demand a leadership shake-up, and between the small anti-Pelosi cadre already in the House Democratic Caucus and a bumper crop of freshmen who have agitated for fresh faces atop the party, they have the numbers to do so.

At least 12 of the new House Democrats have made statements critical of Pelosi on the campaign trail, ranging from a general call for new leadership to a firm refusal to support her election as speaker. Seven more Democratic candidates in that category are running in races yet to be called.

For instance, Abigail Spanberger — who ousted Rep. Dave Brat (R-Va.) on Tuesday — pledged that “under no circumstances” would she vote for Pelosi as speaker while Republicans scrambled to paint her as inexorably connected to Pelosi and the most liberal element of the national Democratic Party.

House Minority Leader Nancy Pelosi (D-Calif.) on Nov. 7 celebrated Democratic victories in the midterms and the diversity of the incoming House Democrats. (Reuters)

Conor Lamb, who beat Rep. Keith Rothfus (R-Pa.), and Joe Cunningham, who claimed the seat held by Rep. Mark Sanford (R-S.C.), aired TV ads touting their opposition to Pelosi.

And even those who did not say flatly they would not vote for Pelosi say it would be a mistake to think they will ultimately support her.

“We don’t want to be disrespectful to anyone who served, particularly a woman who’s broken glass ceilings like Nancy Pelosi,” said Elissa Slotkin, who dispatched Rep. Mike Bishop (R-Mich.) on Tuesday. “But we need to hear what people are telling us, and they’re saying on both sides of the aisle they want a new generation of leadership.”

Already, Republicans are signaling they have no intention of letting up on their political demonization of Pelosi.

In a seemingly sarcastic tweet Wednesday, President Trump suggested Republicans could help get Pelosi elected to keep her on the national stage.

“In all fairness, Nancy Pelosi deserves to be chosen Speaker of the House by the Democrats,” he said. “If they give her a hard time, perhaps we will add some Republican votes. She has earned this great honor!”

But Pelosi has key advantages going into a leadership derby. For one, as of Wednesday morning, no one is running against her. A group of sitting House Democrats have long complained about her leadership — roughly a dozen — but none have yet stepped forward to challenge her.

Some of her toughest internal critics, like Rep. Seth Moulton (Mass.), have specifically ruled out running, and her last challenge, from Rep. Tim Ryan (D-Ohio) after the 2016 election, fell well short.

A speaker typically is elected on the first day of the new Congress by the whole House, meaning the winner will have to get a majority of all those present and voting — both Democrat and Republican. Lawmakers are generally expected to support whoever wins an internal party vote held behind closed doors before the floor election. But they are free to withhold their floor votes to force a different outcome.

That happened in 2015, after House Speaker John A. Boehner (R-Ohio) announced his resignation. Majority Leader Kevin McCarthy (R-Calif.) moved to succeed him, but when it became clear he could not get a majority in a floor vote, he withdrew his candidacy, clearing the way for Paul D. Ryan (R-Wis.) to become speaker.

But Pelosi’s case for the gavel after leading her party back to power could be profound. Virtually every House Democrat won on a platform that heavily emphasized protecting the Affordable Care Act — a law Pelosi was instrumental in getting passed and protecting from Republican attacks.

And, as the first female speaker, she will preside over a Democratic caucus that is becoming considerably more female. Dozens of Democratic women won Tuesday, many of them replacing men, and Pelosi has not been shy about highlighting her own pathbreaking status when making her case for the speakership.

“I want women not to ever be afraid to talk about why they think they’d be the best,” she said Tuesday on PBS.

But campaign promises could prove to more compelling than gender for many incoming Democratic women in the chamber. Slotkin said it came down to a matter of “integrity.”

“This idea that somehow . . . we’re going to say one thing on the campaign trail and then arrive in Washington and flip? Either people don’t understand why we ran and why we’re doing this or they’re pretending that, ‘Well, this is just another year,’ ” she said of her call for fresh leadership. “I’ve said it because I believe it, and I’m not going to flip the minute I get to Washington.”

Pelosi allies privately suggest it is possible a leadership shake-up could ensue that addresses the calls for new leadership but leaves Pelosi in the top spot. That could involve a change in the next two slots — occupied by Minority Whip Steny H. Hoyer (Md.) and Assistant Leader James E. Clyburn (S.C.), who are expected to seek the majority leader and majority whip posts, respectively. All three leaders are in their late 70s.

Another possibility is all three move up in lockstep but other changes are made to the Democratic leadership structure, aides say, opening up new posts for younger members who would be in line to take more senior positions in the next Congress. Pelosi, before the election, spoke about being a “transitional” speaker but declined to define what exactly that meant.

Rep. Gerald E. Connolly (D-Va.) said Tuesday the new class will have an outsize effect on how Democrats organize their new leadership.

“If you’re a freshman, newly minted member of Congress tonight, what do you see your mandate as being?” he said. “Presumably you see your mandate as being change. And so you’re going to have to look very carefully at reelecting three very good but long-standing leaders who are getting up there in age. Is that really the first vote you want to cast? It could be a moment of truth for a lot of these freshmen.”