MIKE LEVIN has the perfect hair, wash-and-wear grin and firm yet unthreatening handshake of a seasoned politician. What he lacked, at least by the standards of California’s wealthy 49th district, was money. Paul Kerr, a property investor and one of Mr Levin’s 16 rivals in the primary on June 6th, spent more than $4m of his own money. Another rival, Sara Jacobs, spent more than $1.5m of hers. But one day before the vote, Mr Levin was unfazed. “There is no substitute for a grassroots campaign,” he says in his nondescript office in a nondescript office park in San Clemente as he rattles off the number of phone calls made and homes visited.

Mr Levin finished in second place, slightly ahead of Ms Jacobs, and well behind Diane Harkey, a Republican former state representative. But in California’s jungle primary—in which all candidates, regardless of party, appear on a single ballot, with the top two advancing to the election proper—second place is a victory. Total Democratic votes exceeded Republican; assuming he can consolidate his rivals’ supporters, Mr Levin may well become the first Democrat in 15 years to represent the 49th. Across California and America, Democrats can breathe a little easier this week: they appear to have avoided a catastrophe born of their own enthusiasm and California’s bizarre system.

Introduced in 2010, jungle primaries were intended to encourage moderation. The thinking was that, by avoiding partisan primaries, candidates would have more incentive to play to the centre rather than the fringes. However well-intended, it was no match for America’s toxic national polarisation. Rather than moderating, parties just gamed the system.

Seven of the 23 districts held by Republicans but won in 2016 by Hillary Clinton are in California. In two of them, Republican incumbents attracted viable Republican challengers, which probably would not have happened with a traditional primary. In most of them, Democratic challengers outnumbered Republicans.

A small Republican field facing a large one composed of first-time, relatively evenly matched Democrats threatened “lockouts”, in which the top two finishers by vote-share both come from the party that receives fewer total votes. To flip the House in November, Democrats need to pick up 24 seats; lockouts would have made their road back to a majority significantly rockier.

Although the official results may not be known for weeks (California accepts mail-in ballots postmarked on election day), all seven Republican-held Clinton districts look likely to feature two-party general match-ups. Democrats are unlikely to win a clean sweep, but our model suggests they will take Mr Levin’s 49th, and party workers like their chances in the nearby 39th and 48th. Orange and San Diego Counties have grown more diverse, and their relatively wealthy, well-educated Republicans are not President Donald Trump’s core constituency. Mr Trump’s elimination of the state-and-local tax deduction is an albatross for Republicans in high-tax California.

Republicans found themselves locked out of a California Senate race for the second straight cycle. Dianne Feinstein, the 84-year-old incumbent, will face Kevin de Leon, a progressive state senator, in November. But Republicans avoided a lockout in the governor’s race. John Cox finished second to Gavin Newsom, the lieutenant-governor. Mr Cox has little chance in November, but his presence gives Republicans an incentive to go to the polls and vote for downballot candidates.

Overall, Democrats emerged from America’s biggest primary night in good shape. In New Jersey they drew more voters and chose electable candidates in the three districts they most want to flip. Bob Menendez, the scandal-ridden incumbent senator, saw off a primary challenge by a thin margin. In New Mexico’s safely Democratic first congressional district, Deb Haaland saw off five challengers; in November she will probably become the first Native American woman elected to Congress. And in Missouri Democrats flipped their 42nd state legislative seat since Mr Trump took office. His approval ratings may have gone up a bit, but he is still driving Democrats to the polls.