Ralph Northam's decisive victory in the Virginia governor's race delivers Democrats a much-needed win, a jolt of momentum heading into next year's congressional elections and a taste of the potential energy that could be generated from President Trump's historic unpopularity.

Northam's triumph — along with upset victories by Democrats over Republican incumbents in the state legislature — marks voters' first major repudiation of the Trump administration.

The message from Democratic voters, who came out in droves for an off-year election, was loud and clearly aimed at the president. Even though Northam and his Republican opponent, Ed Gillespie, sought to distance themselves from Trump during the fall campaign, voters used the opportunity to make a statement.

They not only elected a Democratic governor by the largest margin in a generation but also defeated a slew of Republican state legislators. A transgender political neophyte, Danica Roem, knocked off one of Virginia's most prominent social conservatives, Robert G. Marshall, who had insisted on referring to her with male pronouns throughout the campaign. A daughter of a Salvadoran immigrant defeated a 30-year Air Force veteran incumbent who won previous elections by positioning himself as a moderate Republican who cherished civility.

[Democrat Ralph Northam defeated Ed Gillespie in the race for Virginia governor]

"We are seeing something extraordinary — something even the Northam campaign never anticipated — a phenomenal repudiation of Trump and Trumpism," said Quentin Kidd, who studies Virginia politics and runs the Wason Center for Public Policy at Christopher Newport University in Newport News. "These Democratic wins are in the Hillary districts, those districts that have Republican legislators but went for Clinton last year. This is the Democrats' dream come true."

1 of 41 Full Screen Autoplay Close Skip Ad × The scene during the Virginia elections View Photos Voters in Virginia elected Democrat Ralph Northam over Republican Ed Gillespie as the next governor. Caption Voters in Virginia elected Democrat Ralph Northam over Republican Ed Gillespie as the next governor. Astrid Riecken/For The Washington Post Buy Photo Wait 1 second to continue.

Or, as Jon Favreau, a former speechwriter for President Barack Obama, tweeted, "In case there was any doubt: the Resistance is real."

But while Democrats swept races for New Jersey governor, New York City mayor and all three statewide posts in Virginia, Tuesday's vote offered no definitive guidance about whether the torrent of anti-Trump votes can translate into an effective strategy for Democrats in swing or red states in next year's congressional elections.

No Republican has won a statewide election in Virginia since 2009, and what was long considered a swing state is now represented by two Democratic senators, has elected Democratic governors in four of the past five cycles, and is governed by a legislature that took a big step back from Republican dominance toward relative balance Tuesday.

Some Democrats cheered the Virginia results as a sign of things to come, noting that 23 House Republicans hold seats in districts Democrat Hillary Clinton won last year. The lesson is: Be afraid, be very afraid," said Rep. Gerald E. Connolly (D-Va.), who has represented his Fairfax County district since 2009. "Something is coming. There will be a day of reckoning."

But others warned that the Virginia results may say little about Democratic appeal beyond the mostly coastal states where Clinton did well. "Everything's coming down to geography," said Dave "Mudcat" Saunders, a longtime Democratic political consultant in Virginia whose base in the state's rural south went heavily for Gillespie.

[Anti-Trump backlash fuels a Democratic sweep in Virginia and elections across the country]

"This is the triumph of Clintonism and the urban crescent strategy. The Democrats are just going after the heavily populated areas and the college graduates. All their wins tonight are in the new Virginia, where people moved to from out of state, and the party is saying the hell with the rest of the state."

The shape of Northam's victory gave Democrats both hope and pause. He drew larger portions of the vote than Clinton did in every region of Virginia, outperforming her especially among young people and white women with college degrees, according to preliminary exit polls. But Northam failed to make gains in Democratic weak spots such as with rural and less-educated voters.

The Virginia vote left both parties deeply divided. Despite the win, Democrats remain split between those who thought Northam's moderate approach and quiet manner provided a welcome salve to Trump's disruptive style, and others who argued that the Democrats would have done far better had they taken a more confrontational, progressive- ­populist approach in the style of Bernie Sanders or Northam's primary opponent, former congressman Tom Perriello.

"Just like we had to absorb the tea party, the Democrats now still have to go through their herbal tea party phase," said former Republican congressman Tom Davis, who for many years represented Northern Virginia. "But what they saw tonight is that people are looking for uniters, not dividers."

For Republicans, Tuesday's thrashing instantly quieted the excitement many had felt as Gillespie tried to achieve what former White House adviser Stephen K. Bannon called "Trumpism without Trump." Gillespie, the consummate establishment figure, was a D.C. lobbyist and former head of the Republican National Committee, and he for a time led the party's effort to reach out to Hispanics and diversify the base. But this fall, he sought to pitch himself to Never Trump moderates as a serious advocate for tax cuts even as he rebranded himself for the Trump base as a fire-breathing fighter defending Confederate monuments and attacking criminal gangs of undocumented Hispanic immigrants.

[Republicans seek new path after failure of Gillespie’s ‘Trumpism without Trump’]

It didn't work, as Gillespie lost Virginia by almost twice the margin by which Trump lost the state. Gillespie maintained the basic outline of Trump's coalition — winning among men, older voters, whites, people with less than a college education and people in gun-owning households, according to network exit polls — but he was flat-out crushed in black and Hispanic areas and in many of the state's burgeoning suburbs, as well.

As a moderate Republican who has long argued for his party to seek out Latino and immigrant support, Davis said Tuesday night that regarding confidence in his own rationale, "I'm in a much better place tonight." Republicans who, like Gillespie, once supported a bigger tent and then pivoted to a Trumpian issue agenda "will be judged by the last image people see," Davis said.

Davis said Republicans must now realize that half of Virginia "is essentially New Jersey and the Trump people can't insist on ideological rigidity. The Trump voters are still important, but they weren't enough to win here last year, and they certainly weren't enough tonight. Our party is alienating every ethnic voter, and if we're not careful, Virginia will become another California, where we don't matter at all."

But there was no sign Tuesday night that the president or his supporters were eager to shift course. "Ed Gillespie worked hard but did not embrace me or what I stand for," Trump tweeted after the results came clear. "With the economy doing record numbers, we will continue to win, even bigger than before!"

[Trump tweets that failed Virginia GOP gubernatorial candidate ‘did not embrace me’]

Trump supporter Ken Cuccinelli, Virginia's former attorney general, said that Trumpism is far from dead but that its continued electoral success depends entirely on the ability of Republicans in Congress to score some big victories.

Gillespie "suffered mightily from the utter failure of the Republicans in Washington to do what they said they'd do," Cuccinelli said. "Trump is Trump — let's not kid ourselves that he's going to make any changes. It's up to the Republicans in Congress. If they can't deliver to their voters, those voters simply won't come out, and that should scare the bejesus out of the Republicans in Washington."

Even amid their evening of celebration, some Democrats worried that the Virginia victory would mask the fact that the party has still not found a way to connect with voters between the coasts.

Stanley Greenberg, a longtime Democratic campaign strategist, said Northam was "running as Hillary Clinton. It's the Republicans who talk about the economy, not the Democrats." Northam's emphasis on Virginia's economic success under Gov. Terry McAuliffe (D) sent an alienating message to struggling working-class voters who live beyond the affluent suburbs, Greenberg said.

"The Democratic elites mostly live in very dynamic metro areas, and they don't wake up hungering for change," said Greenberg, who was a pollster for President Bill Clinton and Al Gore and informally advised the Hillary Clinton campaign. "If you don't give people some sense that you are going to make their lives economically better . . . then they are going to give more of an audience to the argument Trump and Gillespie made."

On paper, a Democratic victory may have seemed inevitable in Virginia. The history and math were lined up solidly against Gillespie and the Republicans. Virginia was the only Southern state Clinton won last year, Trump remains deeply unpopular there, and Virginians have a long history of turning against the party of the new president.

[Poll: Trump’s performance lags behind even tepid public expectations]

But the campaign didn't follow that script. Northam proved to be a reserved, polite figure — ­Esquire's Charles Pierce called him "more than a little charisma-challenged on his best day" — and his TV ads presented him as a good doctor but said little about how he'd address the economic collapse of Virginia's rural regions.

Northam's path to victory was pocked with land mines. Last week, Democracy for America, a Democratic activist network with 1 million members, halted its work for Northam. The group accused him of running a racist campaign because he reacted to harsh GOP ads alleging that he favored "sanctuary cities" by saying he would indeed sign a ban on them if a Virginia city declared it would not enforce federal immigration law. (Virginia has no sanctuary cities.)

Northam seemed buffeted by harsh winds from both directions — ideological purists on his left and Republicans who painted him as soft on crime. But despite Gillespie's aggressive ad campaign, which slammed Northam as soft on pedophiles and too lenient toward the Latino MS-13 gang, Democrats came out in force to make their statement.

Under Gillespie, "MS-13 and crime will be gone," Trump promised in an Election Day tweet.

Virginians weren't buying it.

Read more:

Republicans seek new path after failure of Gillespie’s ‘Trumpism without Trump’

Trump just made a bad night for Republicans much worse for himself

Complete results for the Virginia 2017 election