LOS ANGELES—Democrat Gavin Newsom won Tuesday’s primary in the race for California governor and Republican John Cox finished in a strong second place, ensuring Republicans won’t be shut out of the race to replace retiring Gov. Jerry Brown.

With a major boost from President Donald Trump’s endorsement, Cox consolidated Republicans and edged past Democrat Antonio Villaraigosa, an early favorite to advance.

But Cox faces long odds in deeply liberal California, where Republicans are increasingly marginalized in state politics.

The race is one of hundreds of contests across the state that could solidify Democratic dominance and reshape the fight for control of the U.S. Congress.

Newsom, the former San Francisco mayor, was the first candidate to announce a bid for governor more than three years ago and was strongly favored for the top slot. He leaned heavily on his decision in 2004 to issue marriage licenses to same-sex couples in San Francisco, touching off years of debate over gay marriage in California and around the country.

In victory, Newsom wasted no time framing the general election as a fight with Trump.

“We’re engaged in an epic battle, and it looks like voters will have a real choice this November — between a governor who is going to stand up against Donald Trump and a foot solider in his war on California,” Newsom told cheering supporters at his victory rally in San Francisco’s Mission District.

Because of California’s “jungle primary ,” the top two vote-getters — regardless of party — advance to a runoff in November.

The election is pivotal for Republicans looking to end their mounting struggles and gain a stronger foothold in the nation’s largest state. For Democrats, who risk getting shut out of key congressional races, it has massive implications for their push to retake control of the U.S. House.

Democrats need to gain 23 districts nationally to flip the majority in the House, and a key part of their strategy is expanding their 39-14 advantage in the home state of Democratic leader Nancy Pelosi.

The key battlegrounds are seven districts, mostly in Southern California, where Hillary Clinton defeated then-candidate Donald Trump in the 2016 presidential race, making the districts targets this year.

Democrats hope to avoid their nightmare scenario — the vote is split among a crowded field of Democrats and two Republicans get the only slots in the November election.

U.S. Sen. Dianne Feinstein is seeking another six-year term at age 84 and is expected to cruise into November when her likely opponent will be fellow Democrat Kevin de Leon, the former state Senate leader. There are 11 unknown Republicans in the race and none was backed by the party.

Elsewhere, San Francisco will choose a new leader following the sudden death of Mayor Ed Lee, and a Northern California judge, Aaron Persky, faces a recall for the light sentence he gave a former Stanford University swimmer who sexually assaulted a drunken woman.

In the race for governor, Cox defeated Villaraigosa, who was an early favorite to advance but trailed in recent months despite more than $20 million in spending on his behalf by charter school advocates.

Cox, a businessman from San Diego has run unsuccessfully for a number of offices in his native Illinois but gained footing among California Republicans as the campaign progressed. He and Travis Allen both aligned with Trump — Allen repeatedly noted Cox voted for Libertarian Gary Johnson in the 2016 presidential election; Cox said he regrets the choice.

“This is only the first step to turning around this state and taking back California for all Californians,” Cox told supporters in San Diego.

Trump is a popular punching bag for Democrats and unpopular with independents but maintains strong support and loyalty from the GOP base.

“I don’t think there will be a blue wave at all,” registered Republican Keith Smith, 66, said outside a Solana Beach polling place where he voted for Cox.

The campaign played out largely under the radar despite millions of dollars in spending by candidates and their independent supporters. The closing days of the race were marked as much by dueling complaints over that spending as by differences between the candidates, their priorities and their styles of governing.

Sean Spicer, 42, a San Diego resident who works in marketing, said he voted because it’s a civic duty — though he doesn’t like California’s top two primary system and said it is showing its shortcomings this year.

“We have 7,000 candidates vying for governor and so the top two primary system means you end up voting for people who you think can win not who you believe in,” he said.

Evelyn Corado, a 50-year-old preschool teacher from Huntington Beach and naturalized U.S. citizen from El Salvador, chose Villaraigosa for governor.

“He was already mayor of Los Angeles and I saw him do a lot for the Hispanic community,” she said after casting her ballot.

___

AP reporters Julie Watson in San Diego, Amy Taxin in Huntington Beach, Olga Rodriguez in San Francisco, and Amanda Lee Myers and John Antczak in Los Angeles contributed to this report.

___

Sign up for “Politics in Focus,” a weekly newsletter showcasing the AP’s best political reporting from around the country leading up to the midterm elections: https://bit.ly/2ICEr3D

Your support matters…

Independent journalism is under threat and overshadowed by heavily funded mainstream media.

You can help level the playing field. Become a member.

Your tax-deductible contribution keeps us digging beneath the headlines to give you thought-provoking, investigative reporting and analysis that unearths what's really happening- without compromise.

Give today to support our courageous, independent journalists.

SUPPORT TRUTHDIG