Virginia Democratic Lt. Gov. Ralph Northam has won the race for governor of that state on Tuesday, defeating Republican Ed Gillespie and dealing a blow to the GOP nationwide, and especially to President Donald Trump.

"We live in a very diverse society -- it is getting more diverse every day. It is that diverse society that makes this country great," Northam said in his victory speech. "And as long as I'm governor, I will make sure that we're inclusive, that we welcome people to the Commonwealth of Virginia. Our lights will be on. Our doors will be open."

Late Tuesday night, Northam led by nine points, having won 54% of the vote to Gillespie's 45% with 99% of precincts reporting. Northam's margin of victory stunned political analysts and pollsters, many of whom had predicted that the race would be extremely tight.

The campaign to succeed term-limited Democratic Gov. Terry McAuliffe was seen as an early test of Trump's influence in states like Virginia, where his 38 percent approval rating statewide mirrors his approval rating in a recent nationwide NBC News/Wall Street Journal poll.

Much of Northam's electoral strategy revolved around tying Gillespie to Trump, which he did in nearly all of his major campaign ads. "Ed Gillespie supports Donald Trump's plan to take money out of Virginia's public schools, his plan to roll back our clean water and clean air protections. And Ed Gillespie supports Donald Trump's plan to take health care away from thousands of Virginians," said the narrator of one of Northam's last campaign ads.

But if Northam's strategy was to tie Gillespie to Trump, Gillespie's strategy was to tie himself to Trump even more tightly.

A former lobbyist who once warned the GOP against becoming an "anti-immigration party," Gillespie chose to abandon his more moderate past positions in order to campaign as a die-hard Trump Republican.

Gillespie's campaign embraced many of the same divisive cultural issues that Trump has focused on in recent months, running ads that attacked players in the National Football League who protested during the national anthem, and warning voters that Northam would allow violent Central American criminal gangs to flourish in "sanctuary cities."

Meanwhile, Trump has served as a kind of echo chamber for Gillespie, amplifying his campaign themes and broadcasting them onto the national stage.

"Ralph Northam will allow crime to be rampant in Virginia," Trump wrote on Twitter Tuesday morning. Moments later, he tweeted that should Gillespie win, he would "totally turn around the high crime and poor economic performance of VA. MS-13 and crime will be gone."

Trump tweet: Ralph Northam will allow crime to be rampant in Virginia. He's weak on crime, weak on our GREAT VETS, Anti-Second Amendment....

Trump tweet 2: .@EdWGillespie will totally turn around the high crime and poor economic performance of VA. MS-13 and crime will be gone. Vote today, ASAP!

Northam's win also bodes well for the Democrats' chances to reclaim a majority in the House in 2018, a prospect once viewed as nearly impossible. Now, buoyed by Trump's record-low approval ratings and GOP struggles to enact significant legislation, Democrats' chances are looking up.

In mid-October, the nonpartisan Cook Political Report credited a surge in Democratic momentum and candidate recruitment for its decision to shift its closely watched ratings of 12 House races to reflect more favorable conditions for Democrats.

Northam will be sworn in Jan. 13, 2018, for a term that expires in January 2022. By Virginia law, he cannot run for re-election to a consecutive term but can run again in eight years.

Clarification: This story was revised to clarify that Virginia governors cannot serve consecutive terms.