California gubernatorial candidate Gavin NewsomJeff Chiu / AP

California’s unusual election system probably won’t determine which party controls the House of Representatives next year after all.

Democrats on Tuesday night seemed poised to advance to the general election in every competitive House battleground in the state, easing fears that a glut of candidates would lock the party out of crucial pickup opportunities in its quest for the majority. Republicans had their own cause for relief: With a late push from President Trump, the GOP gubernatorial candidate John Cox secured a place on the November ballot and ensured the party a top-of-the-ticket standard-bearer.

In California’s “top two” primary, no party is guaranteed a spot in the general election. Tuesday’s first round was open to all voters, and the two candidates with the most votes in each race are now advancing to the second and final round in November. In heavily Democratic or Republican districts, the system is designed to pit candidates of the same party against each other in the general election to create more competitive races.

But the top-two posed an additional threat to Democrats this year, as anti-Trump enthusiasm spawned a surge of qualified candidates in Republican-held districts that Hillary Clinton carried in 2016, including three in and around Orange County in Southern California. The fear was that the Democrats would split their votes and allow two Republicans to capture the top spots. Democrats need to pick up 23 seats to claim the House majority, and several of their best opportunities are in California. In the final week, state Democratic Party Chairman Eric Bauman told me he expected the party to be shut out of “at least a couple” of key races.

State and national party leaders had staged a late intervention—not always on the same side—to try to winnow the fields, persuading some contenders to drop out and pouring millions into ads aimed at elevating their preferred choice.

It apparently worked—but just barely.

In the seat held by Republican Representative Dana Rohrabacher, the two leading Democratic candidates, Harley Rouda and Hans Kierstead, were separated by 73 votes as of Tuesday night, and were ahead of a second Republican candidate, Scott Baugh, by a little more than 1,000. Rohrabacher, considered one of the most vulnerable Republican incumbents in the country, is safely in the general election with 30 percent of the vote, to about 17 percent for Rouda and Kierstead. The state still has to count thousands of mail-in and provisional ballots, a process that could take days. But it appears one of the two Democrats will advance.

In the district that retiring GOP Representative Ed Royce is vacating, Democrat Gil Cisneros was in second place by fewer than 5,000 votes on Tuesday night. He’ll likely face Republican Young Kim in November. Democrats had more breathing room in the district opened by Representative Darrell Issa’s retirement: Three candidates are vying for second place behind Republican Diane Harkey, guaranteeing the party a spot in November.

Democratic operatives were cautiously optimistic that they had avoided a nightmare. “As we await final results in multiple districts, it is clear that Democrats are in a stronger position than ever to take back the House, and winning districts in California will be central to that path,” Tyler Law, a spokesman for the Democratic Congressional Campaign Committee, said in a statement. “For more than a year and a half, the DCCC has been on the ground in California organizing and investing, in order to register voters for the long-term, boost strong Democratic candidates with local support, and ensure that we face the weakest possible Republican candidates in the general.”

Neither major party in California particularly likes the top-two system, in large part because it was explicitly intended to dilute their power to run primaries and pick candidates. But the challenge for Republicans is a different one. Outnumbered both by Democrats and by unaffiliated voters in the Golden State, the GOP in recent years has struggled merely to field credible candidates for the major statewide offices, much less to win them. So it was a small but important victory that Cox captured the second spot in the governor’s race, where he’ll face  Gavin Newsom in the general election. Newsom, the Democratic lieutenant governor and former San Francisco mayor, captured one-third of the primary vote and is the heavy favorite to succeed retiring Governor Jerry Brown, also a Democrat.

Republicans worried that if Cox failed to make the top two, the lack of a GOP candidate for the premier statewide race would depress turnout among the party faithful across the state. In turn, that could imperil Republican chances in the congressional races that might determine the House majority, as well as state legislative and local elections. Cox had previously run for office several times in Illinois before moving to California. His 26 percent on Tuesday was surprisingly strong, easily outpacing former Los Angeles Mayor Antonio Villaraigosa, who won just 13.5 percent. Cox was likely helped by late support from Trump, who tweeted twice in his favor in the closing days of the race and cheered the results on Wednesday morning.

“Great night for Republicans!” the president tweeted. “Congratulations to John Cox on a really big number in California.”

It was not all positive for the GOP, however. Republicans were locked out of the race to challenge Senator Dianne Feinstein’s bid for a fifth full term, as progressive state Senator Kevin de León advanced to November. Feinstein appears well positioned for reelection, having captured nearly 44 percent compared with 11.3 percent for de León.

Democrats were divided over whether they wanted Newsom to face Cox or Villaraigosa in the fall. Newsom had tried to elevate Cox, figuring a weak Republican would be an easier opponent in a strong Democratic year. He argued that Democrats would benefit by not having to divert resources better spent in other races to a nasty intraparty fight for governor. But others in the party, including Bauman, were hoping a GOP lockout at the top would help them down the ballot.

The top-two system didn’t wreak as much havoc on Tuesday as the parties feared. But another election innovation appeared to have a big impact in the race for mayor of San Francisco. The city uses ranked-choice voting, which creates an instant runoff if no candidate is the first choice of more than 50 percent of voters. London Breed, the Board of Supervisors president, captured 35.6 percent of first-choice votes on Tuesday—nearly 10 percent more than her nearest rival. But once the ranked-preference system kicked in, she was trailing former state Senator Mark Leno by the thinnest of margins, 50.42 percent to 49.58 percent, according to the San Francisco Chronicle. The race remains too close to call, as the city must count thousands of mail-in ballots that could shift the outcome.

Either Breed or Leno would be a historic winner in San Francisco: Breed would be the first African American woman elected mayor, while Leno would be the first openly gay man. The race is a special election to replace the late Mayor Ed Lee, who died in December in the middle of his second term. Breed had been the frontrunner, but Leno and another candidate, Jane Kim, took advantage of the ranked-choice system by teaming up and endorsing each other as their second choice. The gambit may end up electing Leno: More than three out of four Kim voters put him as their second choice. After the first round of balloting, the candidate with the fewest votes is eliminated and the second choices are added to the remaining contenders’ totals. The process continues until one candidate wins a majority.

Ranked-choice voting is used in a number of cities, and next week it will get its first statewide test run in Maine’s primary elections. Later on Wednesday, advocates for election reform are expected to call for its adoption across California as part of the nonpartisan system voters approved by referendum eight years ago, which ushered in the top-two. Whether voters are ready for another change is unclear; Democratic leaders already are planning a push in 2020 to scrap the top-two system and return to some version of a traditional party primary.

The top-two system caused the parties plenty of headaches leading up to Tuesday’s primary. But ultimately, it seems it didn’t change much in the races that will determine the balance of power in Congress: They’ll likely be waged in November much as they have been for more than a century, with one Democrat and one Republican battling each other for the chance to go to Washington.

We want to hear what you think about this article. Submit a letter to the editor or write to letters@theatlantic.com.