FAIRFAX, Va. — After stumbling in the final stretch of the campaign, Democrat Ralph Northam defeated Republican Ed Gillespie Tuesday in Virginia’s gubernatorial election.

Hit by the Right for being lax on crime, and by the Left for making a politically questionable vow to ban sanctuary cities with just days to go before Election Day, Northam secured a critical win for Democrats. Democrats also easily won the New Jersey governor's race, as was expected.

"Virginia has told us to end the divisiveness," Northam said to a pumped up crowd of his supporters at George Mason University. "That we will not condone hatred and bigotry and to end the politics that have torn this country apart."

Northam won by roughly a nine point margin statewide and beat Gillespie by 20 points in the once-reliably Republican Loudoun County. It was one of the swing counties Gillespie would have needed to win to cause an upset. Northam's decisive victory gives a much needed boost to Democrats after the blow 2016 delivered to the party's psyche.

"The Democratic Party is back my friends," said Democratic National Committee Chairman Tom Perez.

Perhaps more telling than Northam's win, however, are the gains Democrats made in Virginia's statehouse. Democrats were expecting to pick up roughly six seats in the House of Delegates but by time of publication had picked up 14 seats. Democratic socialist Lee Carter defeated House GOP whip Jackson Miller. Democrat Danica Roem became the first openly transgender woman elected in Virginia, ousting incumbent Del. Robert Marshall.

House of Delegates Democratic Leader David Toscano called the pickups a "tsunami."

"Virginia is the bellwether for 2018," Toscano told reporters. "It’s going to tell rest of the country that Democrats have woken up; we’re not going to take this anymore and we’re going to field candidates all around this country."

Toscano and fellow House of Delegates member Charniele Herring called Roem's defeat of Marshall — who called himself Virginia's "chief homophobe" and authored a "bathroom bill" — particularly symbolic.

"It’s historic," Herring said. "It sends a message to politicians everywhere that the politics of bigotry is over."

The nation turned its attention to Virginia as Democrats called on voters to reject hate, bigotry, and racism, slamming Gillespie for running a racially divisive campaign, in which he pledged to crack down on undocumented immigrants and Hispanic gangs, and protect Confederate statues. Gillespie once urged Republicans to be more welcoming to minorities but in an ad released in September he attacked Northam for protecting sanctuary cities and letting “dangerous illegal immigrants back on the street," claims detractors described as misleading at best.

Early on in the campaign, Northam called President Trump a “narcissistic maniac” but scaled back his rhetoric as the general election approached. Feeling pressure to appeal to more centrist Democrats and Trump voters with just six days to go, Northam said he’d support legislation banning sanctuary cities.

That prompted outrage from progressive group Democracy for America, which said it would end “any work to directly aid” Northam’s campaign. The left-leaning group’s executive director called Northam “gutless” and “racist” for his remarks. Howard Dean, who founded DFA, called its move against Northam “incredibly stupid.” And less than one week out, fresh allegations from a former interim chairwoman of the Democratic National Committee that the 2016 presidential primary was “unethical” forced Democrats into damage-control mode.

Heading into Tuesday, Northam’s lead in the race dropped to roughly a 3 point edge, worrying Democrats that once again they’d lose a race they were positive they had all sewn up just months ago. Virginia was the one Southern state Hillary Clinton carried in 2016, winning the state by 5 points. Trump’s unpopularity in the state was also a boon to Democrats. Still, without leaning on the president’s name, Gillespie appeared close to upsetting Northam by embracing the themes of Trump’s presidential campaign.

There was no lack of money for Northam. As of October, he raised roughly $34 million and the DNC poured $1.5 million into the state for Democrats up and down the ballot.

Northam’s victory coupled with large gains in the House of Delegates will likely quiet dissenting wings of the party who have grown frustrated over the slow-walking of major reforms they want implemented — but it won’t last long.

"I didn't hear a word during my last four days in Virginia — from anybody -- about Donna Brazile," Perez told reporters later, referring to accusations made by the former interim DNC chairwoman that the 2016 presidential primary process was unethical. "They were looking forward. That stuff's over."

Liberals cheered Northam's win but warned that Democrats need to "learn the correct lessons for 2018."

"Progressives proved that the way to win a Democratic Congress in 2018 is to field inspiring and diverse candidates who connect with voters on bold, popular ideas like expanding Medicare and higher wages for workers," said Stephanie Taylor, co-founder of the Progressive Change Campaign Committee.

Democrats pointed to the Virginia contest as their first real chance to send a message that the party can win in the Trump era and will give them momentum as midterm races heat up.

Though Northam’s win helps Democrats prepare their strategy for 2018, the kumbaya moment will be brief among Democrats, who still have a lot of rebuilding ahead of them.