WASHINGTON — Virginia Lt. Gov. Ralph Northam won the Virginia governor’s race Tuesday, beating GOP candidate Ed Gillespie convincingly in the first competitive statewide election since President Trump’s election.

Democratic gubernatorial candidate Lt. Gov. Ralph Northam, left, gets a hug from a supporter as his wife, Pam, right, looks on after voting in Norfolk, Va., on Nov. 7, 2017. Northam faces Republican Ed Gillespie.

The election marks a major win for Democrats who were badly in need of a rebound after the 2016 presidential election and looked to the Virginia race as a referendum on Trump’s policies. Northam beat Gillespie by about 9 percentage points, while Democrats also swept races for lieutenant governor and attorney general, according to the state Department of Elections.

"Virginia has told us to end the divisiveness, that we will not condone hatred and bigotry and to end the politics that have torn this country apart," Northam, 58, a pediatric neurologist and former Army physician, told his supporters at his victory party.

In New Jersey, Democratic gubernatorial candidate Phil Murphy beat Republican Lt. Gov. Kim Guadagno, as expected, after leading by an average of 14.4 points in the run-up to Election Day.

The Virginia race had been much closer, with Northam leading Gillespie, a former chairman of the Republican National Committee, by 3.3 points, according to RealClearPolitics average of recent polls.

Democrats also made significant gains in Virginia's House of Delegates. They include Danica Roem, who will be the nation's first openly transgender state lawmaker, elected to replace Del. Robert G. "Bob" Marshall, who called himself Virginia's "chief homophobe."

"The Democratic party is back, my friends," Democratic National Committee Chairman Tom Perez shouted over a cheering crowd at Northam's victory party. "We’re back big-time. We’re organizing everywhere. We’re mobilizing everywhere. We’re leading with our values."

Both parties poured money and staff into the Virginia election, which was seen as a potential bellwether for Trump’s impact on mid-term elections across the country next year. Democrats seeking to link Gillespie to Trump cast the election as a chance to stand up to “Trump, Gillespie and hate.”

Former Vice President Biden hailed a "resounding defeat" for Trump.

"Voters around the country rejected the ugly politics we have seen this past year," Biden tweeted. "Instead, they chose candidates who unite and inspire us."

Trump, who is traveling in South Korea, quickly weighed in on the results, distancing himself from the Virginia race.

"Ed Gillespie worked hard but did not embrace me or what I stand for," he tweeted. "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!"

Northam told reporters after voting in Norfolk that he was confident it will be “a good day for Democrats.” At his rally, he said Virginians want a leader who will push for good jobs, access to education, affordable health care, a clean environment and a safe community "where there are not guns on ever street corner." He said his administration will also promote a diverse and “inclusive" state.

"As long as I’m governor, I will make sure that we’re inclusive, that we welcome people to the commonwealth of Virginia," he told supporters. "Our lights will be on, our doors will be open."

Gillespie, a former lobbyist who also served as counselor to George W. Bush, told his supporters Tuesday night that he called Northam to congratulate him and and offer his help. 

"Governor-elect Northam is a good man and I appreciate his service to our country and our commonwealth and I wish him nothing but the best success as our 73rd governor," Gillespie said.

Ed Gillespie shakes hands with a poll worker after casting his vote in the gymnasium at Washington Mill Elementary School on Nov. 7, 2017, in Alexandria, Va.

Gillespie, viewed as an establishment Republican, had distanced himself from Trump, though he said during a Fox News interview that he appreciated Trump’s support.

Trump didn’t campaign in Virginia for Gillespie, but he tweeted several supportive messages during the campaign. On Monday, he tweeted that the Virginia economy would come “roaring” back with Gillespie. And Tuesday, he took a break from his Asia trip to attack Northam as soft on crime.

“Ralph Northam will allow crime to be rampant in Virginia,” he tweeted. “He’s weak on crime, weak on our GREAT VETS, Anti-Second Amendment....”

In robo-calls that played Monday and Tuesday, Trump pledged that Gillespie would be “tough on crime and on the border” while Northam will be “a total disaster for your state,” according to a Politico report the Gillespie campaign confirmed.

In an apparent appeal to Trump’s base, Gillespie’s ads portrayed Northam’s policies as “risky” and “dangerous” on public safety and immigration. One blamed Northam for increasing the threat of the gang MS-13  — a key focus of Trump’s — because Northam, as lieutenant governor, cast a tie-breaking vote against legislation to pre-emptively ban “sanctuary cities,” which decline to enforce federal immigration laws.

Fauquier County gunsmith Andy Rusk signs in to vote in Virginia's gubernatorial election, Nov. 7, 2017.

Rep. Gerald Connolly, D-Va., said Virginians rejected Trump's style of politics.

"Ralph Northam was the perfect antidote to the orange-headed guy in the White House," he said at Northam's party. "We have a great opportunity to make a national statement, Virginia, and we’re doing it tonight. This is the beginning. We choose to resist by voting. Look out, 2018."

Read more:

Progressive group pulls aid to Virginia's Democratic candidate for governor over ‘gutless’ position

Trump casts long shadow over Virginia governor’s race

Though Republicans control the state’s General Assembly, Democrats have carried Virginia in the last three presidential elections and in three of the last four governor’s races. The current governor, Terry McAuliffe, is a Democrat and is term-limited. Democratic presidential nominee Hillary Clinton carried the state in 2016 by 5 points.

Clinton tweeted her support for Northam and other Democrats, urging people to get out and vote.

“I always vote, rain or shine,” Sally Carson, a 25-year Virginia resident, said at an Arlington polling station as the rain picked up. Carson said having a Democratic governor is important to her because “Republicans aren’t getting anything done.”

Eva Reynolds, of Falls Church, said Northam’s support of more sustainable energy and environmentally friendly policies are the main reasons she was voting for him.

"[Ed Gillespie] seems very anti-immigrant and is siding with Trump in a lot of ways that I'm not keen on at all," she said.

Contributing: Jasmine Khayami and Casey Egan, Medill News Service