– Democrats enhanced their prospects for winning control of the House in Tuesday’s coast-to-coast primaries, skirting potential calamity in California and lining up likely gains in New Jersey and possible victories in Iowa and New Mexico.

The Democratic Party had feared disaster in California, where a “jungle primary” gives the November ballot to the top two finishers in the primary, regardless of party. But Democratic contenders were able to leverage financial and strategic help from the national party to weather the winnowing primary and ensure that they will field candidates in multiple California House districts that they will most likely need to win control in November.

“Even though Democrats had to spend a few million dollars, crisis averted,” said Nathan Gonzales, a veteran House race handicapper and the editor of the Inside Elections newsletter.

Republicans avoided their own worst-case scenario as well, securing a spot in the California governor’s race, which should help bring Republican voters to the polls this fall to vote for Republican House candidates. Republicans missed a slot on the ballot to challenge Sen. Dianne Feinstein’s re-election bid, but a shutout in both California’s Senate race and its contest for governor could have severely depressed conservative turnout.

Republican voters also chose strong candidates in Southern California for the showdown in November.

The Democrats had more on the line, and more to celebrate. They will now be able to mount challenges in places where they feared being shut out, including open seats near San Diego and Los Angeles and districts represented by Republican incumbents in Orange County, Los Angeles County and around Modesto. Between California and New Jersey, Democrats will contend for at least 10 Republican-held seats, nearly half of the 23 they need for control.

While California was the focal point of Tuesday’s voting, New Jersey was one of a handful of other states where the battle for the House was also joined, including Iowa and New Mexico.

In New Jersey, Democrats settled on well-funded candidates who they believe are likely to prevail in elections for seats being vacated by Reps. Rodney Frelinghuysen and Frank LoBiondo. They also intend to mount serious challenges to incumbents Leonard Lance and Tom MacArthur, the latter a lawmaker who has closely aligned himself with President Donald Trump.

“The results last night not only in California but in New Jersey, Iowa and New Mexico ultimately come down to really strong Democratic candidates getting through with pretty overwhelming support in states where the voters weren’t split among multiple candidates,” said Meredith Kelly, the communications director for the Democratic Congressional Campaign Committee.

Republicans saw some positive developments Tuesday as well. In the California governor’s race, John Cox, a Republican, secured a spot on the ballot to face Gavin Newsom, the Democratic lieutenant governor.

In an early-morning tweet Wednesday, Trump embraced Cox and tried to counter the widely prevailing view that Democrats had dodged an electoral bullet.

“Great night for Republicans! Congratulations to John Cox on a really big number in California. He can win,” Trump tweeted. “So much for the big Blue Wave, it may be a big Red Wave. Working hard!”

In addition, congressional Republicans were enthusiastic about their own contenders in California, including Young Kim, a Korean-American who was the top vote-getter in the primary to replace Rep. Ed Royce, another retiring Republican in a district that is nearly 30 percent Asian.

“As a businesswoman and a longtime aide to Congressman Ed Royce, Young understands Southern California families’ needs,” said Rep. Steve Stivers of Ohio, the chairman of the National Republican Congressional Committee.

Another female candidate, Diane Harkey, was the top vote-getter in the San Diego County district being vacated by Rep. Darrell Issa.

While Democrats managed to push their candidates through the dicey process, their success in the California races is not guaranteed even though at least seven Republican-held districts in play were carried by Hillary Clinton in 2016. Despite opposition to Trump, the districts remain dominated by Republican voters. And Democrats did not always get their preferred candidate, with more progressive candidates prevailing in some districts.