LOS ANGELES — Gavin Newsom, the Democratic lieutenant governor and former mayor of San Francisco, took a major step Tuesday in his bid to become California’s next governor, capturing one of two spots on the November ballot as the state moved closer to the end of the era of Gov. Jerry Brown.

John Cox, a Republican businessman backed by President Trump, captured the other spot, setting up what is — at best — a very long-shot bid for Mr. Cox in a decidedly Democratic state where Mr. Trump lost by nearly four million votes.

Mr. Cox’s showing represented a major tactical victory for national Republicans as they seek to protect seven Republican-held congressional seats in California that Democrats are targeting as they try to recapture the House. Republican leaders, including Kevin McCarthy, the House majority leader who comes from central California, had feared that having no Republicans running for a high-profile statewide office would diminish turnout among party voters in the fall.

Importantly, Democrats seemed poised to avoid the disaster they feared in House races: Being shut out of the November balloting under the state’s so-called “top-two’’ primary system, in which only the top two finishers advance to the general election. But many of the districts had crowded primaries and in some of them votes were still being counted early Wednesday morning.