A centrist Democrat’s comfortable victory Tuesday in the Virginia gubernatorial election means a lot to a down-and-out party struggling to regain national power after a disastrous 2016. And it should throw a scare into Republicans worried that public disapproval of President Donald Trump could foil efforts to hold on to control of both houses of Congress next year.

The victory of Lt. Gov. Ralph Northam overcame a Republican challenge modeled on Trump’s race-baiting tactics during his 2016 presidential run. Northam defeated Ed Gillespie, a Republican lobbyist and former national party chairman who adopted Trump’s anti-immigrant nationalism in an effort to excite Republican stalwarts unmoved by his establishment background and message. Gillespie defended Confederate monuments in the state that has more of them than any other, and assailed professional football players who kneel during the national anthem.

The strategy narrowed an early gap in the polls but wasn’t enough to overcome Northam’s huge majorities in the populous suburbs of Washington, D.C., where congressional Republicans may be vulnerable in 2018. Northam’s victory margin of 8 percentage points, fueled by an energetic turnout, was wider than Hillary Clinton’s win over Trump last year and bigger than any recent Democratic triumph in a statewide Virginia race.

Republican disappointment at the result could turn into shock over the next five weeks if more House Republicans, sensing a bad political environment, announce their retirements, and especially if Democrats pull off a huge upset in a special Senate election in overwhelmingly Republican Alabama next month. That would suggest that the Senate, as well as the House, is in play next year.

Democrats, ebullient Tuesday night after the Virginia polls closed, would have been devastated if they’d been unable to parlay Trump’s weak approval ratings into actual election wins.

The Northam victory also gave comfort to centrist Democrats who’d been put on the defensive by their party’s Bernie Sanders wing, which had been arguing that the party should move further left to win majorities in the age of Trump. Sanders supported a more liberal candidate in the Democratic primary earlier this year and refused to endorse Northam, as did some of his activist supporters.

The next Virginia governor is a pediatric neurologist and Army veteran, in the Democratic-mainstream mold of Gov. Terry McAuliffe and Sens. Tim Kaine and Mark Warner. He has resisted liberal pressure to embrace a national single-payer health care plan.

Northam succeeds McAuliffe, who was barred by term limits from seeking a second term. But Democrats picked up a governorship in New Jersey, where a former Goldman Sachs executive and ambassador to Germany, Phil Murphy, defeated Lt. Gov. Kim Guadagno. Murphy will succeed the once-popular Republican Chris Christie, now perhaps the least admired governor.

Republicans still dominate the nation’s statehouses with 33 governors to 16 for Democrats, with an independent in Alaska.

Virginia, once a Democratic stronghold, turned Republican with the rest of the South almost a half-century ago after the civil rights movement. The trend reversed during the last two decades as the population swelled in the politically more progressive Washington surburbs, making Virginia the only Southern state that now tilts reliably Democratic. If the party makes further strides in state legislative races next year, the Northam victory could mean a possible gain of one or two congressional seats in the redistricting after the 2020 census.

Trump, whose campaign strategist Steve Bannon had praised Gillespie for running a Trump-like campaign, swiftly abandoned the Virginia loser in a post-election tweet from a diplomatic trip to Asia:

“Ed Gillespie worked hard but did not embrace me or what I stand for. Don’t forget, Republicans won 4 out of 4 House seats, and with the economy doing record numbers, we will continue to win, even bigger than before!”

Albert Hunt is a Bloomberg View columnist. He was the executive editor of Bloomberg News, before which he was a reporter, bureau chief and executive Washington editor at the Wall Street Journal.