SAN FRANCISCO—The Democratic Party on Wednesday appeared on track to avoid being shut out of several competitive California House races, escaping pitfalls of the state’s primary election system that would have threatened its fight for control of Congress in November. In a handful of closely watched races Tuesday, a Democratic candidate finished in the top two, ensuring the party will have someone on the general-election ballot, after the party invested millions of dollars to advance some candidates and undercut others. And in the state’s Senate race, Sen. Dianne Feinstein, a five-term lawmaker who was the only Democrat in the Senate facing a serious primary challenge in 2018, was far ahead of the second-place finisher, who was also a Democrat, according to the Associated Press. If those results stand, Republicans would have no Senate candidate on the fall ballot in California. The state’s vote, particularly for its House seats, was being intensely watched by both parties. The deep blue state is the vanguard of opposition to the Trump presidency, and Democrats have designs on seven GOP-held House seats to get them a good part of the way toward a net gain of 23 seats they need to seize control of the chamber. Still, Democrats risked having no candidate on the ballot in a few House districts they hoped to flip, given the large number of Democratic candidates and the state’s all-party primary system, in which the top two vote-getters advance to a November election regardless of party. By early Wednesday, Democrats held second-place positions in several key races, although voter-roll snafus Tuesday and a plethora of tight races mean it could be days before the outcome in key races is known for sure. Ms. Feinstein’s chief challenger is Democratic state Sen. Kevin de Leon, who has argued that the 84-year-old incumbent hasn’t done enough to stand up to President Donald Trump. In a sprawling field of 32 Senate candidates, the top Republican contender was James Bradley, a veteran and head of a health-care startup company. With almost all precincts reporting, Ms. Feinstein had nearly 44% of the vote, while Mr. De Leon had 11% and Mr. Bradley about 9%, the AP said as of Wednesday morning. In all three, Democrats were at risk of becoming victims of their own party’s strength, because anti-Trump sentiment had set off a stampede of candidates for Congress. Party leaders may have averted that outcome in all or most of the races by spending millions in advertising in the closing weeks to ensure the party’s vote wasn’t diluted among too many candidates. The Democrats have a “blue wave” of momentum building for the 2018 midterms, thanks to a motivated base, success in special elections and a low approval rating for President Trump. Will that be enough to take back the House and the Senate?