Sen. Kamala D. Harris of California launched her presidential campaign as a clarion call to the emerging Democratic electorate, especially the women and minorities who had just enjoyed a banner year in the 2018 election.

“You are not invisible,” she said in January, announcing a campaign that would hire a largely nonwhite senior staff and commission a mural of black, Latino and Asian faces for her Baltimore campaign headquarters. “We all stand together.”

But by the time Harris ended her campaign Tuesday, struggling in polls and fundraising, a defensiveness had begun to crowd her message of uplift. She began speaking in her final weeks about the “elephant in the room,” the concern that the nation would not elect a black woman over President Trump.

“I’m ready, but I don’t know if my neighbors are ready,” she said in Greenville, S.C., adopting the voice of a doubting voter. “Oh, it’s going to be so difficult.”

A party that began the presidential cycle having elected more women and minorities to Congress than at any point in history has largely shunned those candidates so far in the presidential campaign, pushing several from the race or the debate lineup. Some activists worry that the Dec. 19 debate could be all-white.

Democratic contenders who kicked off their campaigns promising to break gender barriers, or rally the rainbow coalition of Barack Obama, instead found themselves fighting concerns that the country’s lingering racism or sexism could help reelect Trump.

“I do think this is a real moment of reckoning in the party,” said Jess Morales Rocketto, a veteran of Hillary Clinton’s 2016 campaign who now works for the National Domestic Workers Alliance, most of whose members are immigrants or women of color. “We had the most diverse field in history, and there is an argument that was soundly rejected by voters.”

To a striking degree, Democratic voters appear to be adopting the role of pundits, choosing candidates based on how they believe other voters will act rather than their own preferences, interviews with voters shows.

Still, the nomination is far from settled. Obama trailed Clinton in the polls in late 2007 before going on to win the nomination, and past nominees such as Jimmy Carter in 1976 and John Kerry in 2004 came back from polling deficits the preceding fall. But neither of those candidates was excluded from the party’s debates because of low polling, a prospect that has hit some women and nonwhite candidates particularly hard this year.

Currently, six white candidates, including two women and billionaire financier Tom Steyer, have qualified for the December debate. Two others, businessman Andrew Yang and Rep. Tulsi Gabbard (Hawaii), who are of Asian descent, need one more poll at 4 percent to qualify. Sen. Cory Booker (N.J.), who is black, and former Housing Secretary Julián Castro, who is Latino, are not likely to make the cut. Former Massachusetts governor Deval Patrick, who is black and who entered the race last month, also is not expected to make the stage.

“We have more billionaires onstage than black people,” said former South Carolina state representative Bakari Sellers, who had endorsed Harris. “The Republican top six candidates at this time in 2016 was more diverse than our top six candidates.”

The Republican debate in December 2015 included Sens. Ted Cruz (R-Tex.) and Marco Rubio (R-Fla.), who are Latino, and Ben Carson, the current secretary of housing and urban development, who is black.

Sellers cautioned against buying into fears that Trump would more easily beat a minority candidate. “Trump is an interesting phenomenon: He has actually put the Democratic Party in what I feel is an untenable position by believing we need a white candidate to win,” he said.

Rep. Marcia L. Fudge (D-Ohio), who had endorsed Harris, said journalists and others were disproportionately critical of the senator’s campaign.

“I think we as a party give lip service to diversity, but we really care very little about it,” Fudge said. “I would say for the highest-ranking elected black woman in the country to have gotten the kind of dismissal by so many people, I think is nothing more than misogynistic, as well as in some respects quite racist.”

Strategists and candidates blame the struggles of female and minority candidates on a variety of factors. The initial fury of the women’s marches that greeted Trump’s arrival in Washington has faded, they say. Individual weaknesses were shown by candidates like Harris, who struggled to articulate a consistent campaign message, and Sen. Kirsten Gillibrand (N.Y.), who ran an unabashed women-focused campaign that failed to connect with voters.

Others point to media coverage that they say focused on white working-class male voters and suggested the party’s overriding challenge was to win them back. Candidates like Harris, Castro and Booker, in contrast, have run explicitly on their promise to turn out more urban voters in the general election.

“There is a narrative that has developed in the media about who can best take on Donald Trump, about this moderate working-class white voter in the Midwest,” Castro said in an interview. “I don’t recall any articles that have spent nearly as much time figuring out what happened with the decline in the black vote, looking at Detroit, Milwaukee and Philadelphia.”

The most common explanation, however, has focused on a fear that pops up regularly in focus groups and voter interviews. Both black and white voters regularly express concern that a white man would be best able to take on Trump, given that the general election campaign could awaken the same explosive racial and gender dynamics that characterized the 2016 campaign. Clinton’s loss, which some Democrats blame at least partly on sexism, remains fresh in many minds.

“You do hear over and over again from women in focus groups, ‘I would like to see a female president, but I think it would be harder for a woman to win,’ ” said one Democratic strategist who spoke on the condition of anonymity to discuss private surveys. “People are projecting who people will vote for, who they think will win.”

Some Democratic candidates have directly addressed such fears. Both Castro and Booker have regularly urged Democrats to avoid defaulting to a “safe” choice.

“People have been traumatized by a president who often sounds more like George Wallace than we would hope would sound like George Washington,” Booker said in an interview.

Sen. Elizabeth Warren (Mass.), who has leaned into her history-making quality as potentially the first female president, has made calls for dreaming big and doing hard things a central part of her message. And at the last Democratic debate, Sen. Amy Klobuchar (Minn.) tried to dispel doubts that a woman could take on Trump.

“Women are held to a higher standard — otherwise we could play a game called ‘Name Your Favorite Female President,’ which we can’t do because it has all been men,” Klobuchar said. She cited the example of the House speaker. “If you think a woman can’t beat Donald Trump, Nancy Pelosi does it every single day,” she said.

Karen Finney, a strategist who worked on Clinton’s 2016 campaign, said the recent gains by women and minorities, including the election of Obama and the nomination of Clinton, do not erase the head winds faced by such candidates.

“There is still cultural bias, frankly,” Finney said. “Some of it is unconscious. There is a sexism and some racism about what a leader looks like and who we think can win.”

In public polls, voters give conflicting signals about their association of race and sex with electability. A June Los Angeles Times/USC survey found that when Democratic voters were asked to describe the characteristics of a nominee with the best chance of beating Trump, 68 percent said that imaginary candidate would be white and 70 percent said the person would be a man.

On the other hand, a September Washington Post-ABC News poll found nearly 8 in 10 saying a candidate’s race did not matter in his or her ability to defeat Trump, while nearly 7 in 10 said the same about gender.

Booker and Castro have argued that rules of the nominating process have contributed to the struggles of nonwhite candidates. Castro points to the enormous influence of Iowa and New Hampshire, two overwhelmingly white states, on selecting the nominee.

Booker blames the rules for qualifying for the Democratic debates, established by party Chair Tom Perez, which emphasize polls and grass-roots fundraising. Such guidelines favor candidates with a narrow appeal, Booker says, and force campaigns to shift focus away from their field programs to raise more money.

Perez allowed 20 candidates to attend the first debates, and he has been gradually winnowing the stage. All the networks hosting debates are required by the party to have nonwhite and female representation among the moderators.

Booker argued that for the January debate, the qualifications should be changed to include endorsements in Iowa and other factors like whether a candidate is considered a second or third choice in the state.

“It is unacceptable that there is a true competition in Iowa that you will not get to see right before their caucus,” Booker said. “That incongruence is unacceptable.” The Iowa caucuses are Feb. 3.

Another obstacle for nonwhite candidates has been the staying power of former vice president Joe Biden. He received 27 percent support from Democratic-leaning voters overall in a late October Washington Post-ABC News poll, but 30 percent support among nonwhites and 39 percent support among blacks. Those numbers may shift if he fails to perform well in the early contests in states such as Iowa, where he is polling lower.

Charles Lewis, chairman of the Greenwood County Democratic Party in South Carolina, said many voters in the first Southern state to cast its primary vote feel safer with Biden’s profile.

“I think because he is, of all things, an older white man and this is the South,” said Lewis, who is African American. “People think they rolled the dice on Obama, but now let’s be safe this time and let’s get something done.”

Chelsea Janes and Scott Clement contributed to this report.