SAN FRANCISCO—Democratic Lt. Gov. Gavin Newsom placed first and Republican businessman John Cox second in California’s all-party primary Tuesday, ensuring the GOP won’t be shut out of a top-of-the-ticket fall election to succeed term-limited Gov. Jerry Brown.

Mr. Newsom, who finished with one-third of the vote, is considered the heavy favorite in the November election in this deep-blue state. But GOP leaders were successful in getting behind Mr. Cox, who won just over a quarter oft he vote, working to consolidate Republican support behind him in a sprawling field that had 27 candidates including five Republicans.

“We are very happy with the results, we could not be happier,” California Republican Party Chairman Jim Brulte said in an interview Tuesday night.

On Wednesday morning, President Donald Trump congratulated Mr. Cox on Twitter, calling it a “great night for Republicans!”

Another Democrat, former Los Angeles Mayor Antonio Villaraigosa, fell short of the No. 2 slot behind Mr. Cox.