Despite Hillary Clinton having an almost unassailable lead in the delegates needed to clinch the Democratic presidential nomination, her opponent, Bernie Sanders, celebrated his primary victories and shifted his focus toward California, while speaking in San Jose on May 18. (Video/Reuters; Photo/Matt McClain, The Washington Post)

Despite Hillary Clinton having an almost unassailable lead in the delegates needed to clinch the Democratic presidential nomination, her opponent, Bernie Sanders, celebrated his primary victories and shifted his focus toward California, while speaking in San Jose on May 18. (Video/Reuters; Photo/Matt McClain, The Washington Post)

There is a real chance that Hillary Clinton will have clinched a majority of delegates — and the Democratic nomination — before polls close in the California primary late in the evening of June 7.

But losing one of the country’s most diverse and Democratic states to Sen. Bernie Sanders of Vermont would be such a damaging way to end this tumultuous primary season that Clinton is planning to spend millions there over the next two weeks.

This isn’t exactly what Clinton had hoped to be doing as her party’s July convention in Philadelphia approaches and Republicans ramp up for the general election.

Sanders is pouring a mountain of time and resources into the Golden State in an effort to claim as many of its 475 pledged delegates as possible. He has been crisscrossing the state on and off for a week, attracting tens of thousands of supporters to rallies in Los Angeles, San Diego, Carson and other places. The resonance of his message of economic populism — and his unwavering promise to stay in the race until July — have made it all but impossible for Clinton to turn fully to a general-election contest against presumptive Republican presidential nominee Donald Trump.

“We believe we are going to do something in this campaign that has never, ever been done in the modern history of Democratic politics,” Sanders told reporters after a rally in Los Angeles this week. “We will be holding rallies up and down the state, the central part of the state, that we think will bring out at least 200,000 people. We expect that roughly speaking, some 5 million people will be participating in the Democratic primary on June 7. To win that, you’re going to need about 2.5 million people. And we think we stand a good chance, above and beyond everything else we’re doing, to communicate with about 10 percent of the votes that we need to win here in California.”

1 of 42 Full Screen Autoplay Close Skip Ad × Highlights from Bernie Sanders’s campaign, in pictures View Photos The senator from Vermont is Hillary Clinton’s rival in the contest for the Democratic presidential nomination. Caption The senator from Vermont is Hillary Clinton’s rival in the contest for the Democratic presidential nomination. June 14, 2016 Bernie Sanders arrives at the Capital Hilton to meet with Hillary Clinton in D.C. Matt McClain/The Washington Post Buy Photo Wait 1 second to continue.

[Sanders wins greater say in Democratic platform; names pro-Palestinian activist]

In response, Clinton has deployed a massive effort to keep a once-loyal state from slipping from her grasp. She arrived in California late Monday for a four-day blitz of campaign events and fundraising. She has opened eight offices in the state and filled them with dozens of volunteers and paid operatives. She is running phone banks in seven languages.

Clinton has called in some of her most famous and effective surrogates — beginning with former president Bill Clinton, who has been barnstorming the state since Saturday and will remain through Tuesday for at least seven events. Rep. John Lewis (D-Ga.) has worked the African American community. Former representative Gabrielle Giffords of Arizona and her husband, astronaut Mark Kelly, have focused on gun control. Labor leader Dolores Huerta has campaigned on Clinton’s behalf in the Latino community.

“We have to deal with this election, which is being fueled by the anger of people who feel left out and left behind,” Bill Clinton said during the weekend in Chula Vista, in a clear attempt to address the wave of voter anger that has helped Sanders and Trump more than his wife this year.

[Under the radar, Bill Clinton finds his voice as a supporting actor]

A victory in California would surely strengthen Sanders’s resolve to keep fighting through the convention and further delay Clinton’s ability to unify the party. More significant, losing the nation’s most populous state would deal an embarrassing blow to Clinton that could haunt her in the general election against Trump — even if she clinches the nomination with a victory in New Jersey.

Saturating the state

California voters, who rarely experience this kind of political attention, probably will see a lot of both candidates between now and June 7 for a simple reason: Appearing is cheaper than advertising. Neither campaign is airing television ads, and Clinton’s allies say she probably will spend on television only if Sanders forces her hand.

1 of 46 Full Screen Autoplay Close Skip Ad × Clinton on the campaign trail View Photos The former secretary of state visits key states in her quest to become the Democratic nominee for president. Caption The former secretary of state, senator and first lady is the Democratic nominee for president. July 31, 2016 Hillary Clinton is seen aboard the campaign bus in Cleveland on the third day of a bus tour through Pennsylvania and Ohio. Melina Mara/The Washington Post Buy Photo Wait 1 second to continue.

That means relying on as much earned media as possible by saturating the state’s 11 media markets with candidate and surrogate appearances.

“A rally in California is three people in front of their living-room TV,” said Bob Mulholland, a longtime California Democratic operative and Clinton supporter. “A smart candidate will be hitting two or three media markets a day and getting on TV as much as possible.”

But Clinton and Sanders won’t be participating in another televised debate. Clinton’s campaign announced late Monday that she had declined a Fox News invitation to debate in California next month.

[Hillary Clinton declines invitation to debate Bernie Sanders in California]

Clinton and Sanders say they have run aggressive ground games focused on registration, voting by mail and turning out voters. The Sanders campaign has experienced upheaval in recent weeks. Four top campaign officials — including Sanders’s state director, Michael Ceraso — left the campaign. Ceraso cited differences over the campaign’s organizing strategy.

California’s demographics and economy make it a proxy for much of the rest of the nation — or at least of the nation’s demographic future. About 1 in 9 Americans lives in California, and it is by far the most diverse state in the nation. The state is majority minority, with Latinos making up about 40 percent of the population in addition to a large Asian population and smaller black population. A majority of the Asians in California are immigrants or the children of immigrants.

[Even supporters agree: Clinton has weaknesses as a candidate. What can she do?]

Clinton intends to focus heavily in California on minority communities, which have been loyal to her in other states. The campaign has focused intently on the state’s large Asian American population; five of the seven languages spoken at Clinton’s phone banks target Asian voters.

“She’s got a long-standing relationship with a lot of these communities,” said Buffy Wicks, who was President Obama’s state director in 2008 and is reprising the role for Clinton. “They view her as someone ultimately who gets up and fights every day.”

Sanders thinks that he can appeal to the state’s progressive roots. According to his campaign, the numbers he has been able to draw at rallies — about 16,000 at a recent Sacramento rally — are proof that his message is resonating.

“It’s a heavily Democratic state, it’s a progressive state that likes him on a lot of issues like minimum wage and campaign finance reform, or breaking up banks,” said Sanders spokesman Michael Briggs. “He’s got the boldest proposals on all of those areas.”

Sanders has also weighed in on several statewide issues, including a ballot initiative that would prohibit the state from paying more for prescription drugs than the lowest price paid by the Department of Veterans Affairs, as well as a ballot initiative to legalize marijuana.

A critical issue

Sanders supporters have filed suit in California courts to extend the state’s voter registration deadline — which was Monday — until Election Day, citing confusion about the rules. For Sanders, the issue is crucial.

California has a somewhat open primary that allows voters unaffiliated with a political party to vote in the Democratic primary. Sanders has often performed best in states with primaries that allow independents. But those registered with another political party, including the state’s largest third party, the American Independent Party, will be shut out.

California also allows voters to submit their ballots by mail, which means that the state’s Election Day is a weeks-long affair. From an organizing perspective, the system benefits candidates who have a stronger ground game and can target and track voters who need to return their ballots. It may also give Clinton an advantage because early voting tends to skew toward groups that favor her: older voters and the party faithful.

There is a silver lining for Clinton in a long and difficult primary that forced her to spend more time in California than she expected: a fundraising advantage that should serve her well in the fall, said Clinton backer Chris Lehane, a Democratic strategist who works for Airbnb.

Lehane said the campaign has carefully paired campaign work with meetings and other outreach activities to cultivate two big gold mines of Democratic money in California: the entertainment and tech industries.

“The Clinton campaign has put pieces in place for successful fundraising in the fall, using the primary,” he said.

Democratic strategist Garry South said that the state’s demographics favor Clinton, but the open primary could bring Sanders within a few points of her on June 7.

The Clintons have a long and fruitful relationship with California. Bill Clinton won the state’s Democratic primaries in 1992 and 1996, and in 1992 he began a Democratic general-election winning streak that has continued.

“This is a Clinton state,” South said. “Bill Clinton came to California 60-some times as president. He knew California like a county supervisor.”

Still, although Clinton and her allies hope to win California, they are less concerned about the final outcome, Mulholland said. Clinton won the state in 2008 — and didn’t win the nomination. He also noted that ahead of the 2008 convention in Denver, Clinton won six of the final 10 primaries and caucuses. Sanders probably will rack up a similar track record ahead of the Philadelphia convention.

“Sure, if you don’t ‘win’ a state, for a day or two the press says, ‘She didn’t win a state,’ ” Mulholland said. “We went to Denver and nobody was thinking that.”

David Weigel in Los Angeles contributed to this report.