Washington (AFP) - US Democrats claimed a resounding win Tuesday in a crucial governor's race in Virginia, dealing a blow to Donald Trump's politics of division and testing the president's influence ahead of larger battles in 2018 and 2020.

The marquee race has national ramifications as a test for the Republican Party and their combative leader, and Democrats came out on top.

The race had all the makings of a nailbiter, but in the end Lieutenant Governor Ralph Northam handily defeated his Republican rival Ed Gillespie in the southern battleground state, in a rejection of Trump's policies and his scorched-earth 2016 campaign, whose polarizing tactics have darkened his presidency.

"Fear and division and hatred do not work," the state's current governor, Democrat Terry McAuliffe, told CNN shortly before US networks projected Northam's victory.

With more than 83 percent of precincts reporting, Northam led with 53.15 percent against Gillespie's 45.66 percent.

With a Democrat also projected to win the governor's mansion in New Jersey, the results mark a revival of political fortunes for the party, which had failed to win a number of previous special elections in several states this year triggering concern about how to counter Trump's influence in US politics.

"Tonight we proved that we're stronger when we value and fight for one another," Northam said in a tweet.

The results are an unmistakable boost for a Democratic Party that has been plagued by recent infighting ahead of the 2018 mid-term elections, and show Republicans that coddling the combative Trump comes at a price.

Voters "rejected a Trump-Pence agenda that would take health care away from millions, cut taxes for millionaires and corporations at the expense of the middle class, and fuel bigotry and division at a time when our country needs unity," Democratic National Committee chairman Tom Perez said in a statement.

"Tonight's success is just the beginning."

Virginia voted twice for former president Barack Obama, and Democrat Hillary Clinton carried the state in last year's White House race.

Story continues

An upset victory for Gillespie would have served to validate Trump's aggressive style, and form a blueprint for how mainstream Republicans can embrace Trump issues without necessarily embracing the controversial man himself.

Going forward, they might be forced to rewrite their playbooks.

Gillespie had accused Northam, 58, of failing to curb gang violence, making it easier for sex offenders to purchase guns, and seeking to tear down statues honoring Civil War pro-slavery Confederate secessionists.

Trump took time out from his Asia trip to tweet support for Gillespie, highlighting the hot-button social issues that he hoped would stir his base to vote.

- Trump criticism -

The president has not campaigned with Gillespie, a former Republican Party chief.

But the candidate's many ads, which have fueled debate on race, guns, illegal immigration and the fate of Confederate statues, signal clear alignment with the president.

Trump concluded it was not enough of an embrace of his populist nationalism, tweeted a scathing rebuke of his own party's candidate just minutes after Gillespie lost.

"Ed Gillespie worked hard but did not embrace me or what I stand for," Trump wrote.

If Trump had not proven a drag on Virginia voters, it would demonstrate his power to draw Americans to polls despite poor approval numbers.

Several cities including New York and Manchester were also electing mayors, while a handful of states held elections Tuesday for local lawmakers.

In New Jersey, Democrat Phil Murphy was project to easily win the governor's mansion, as Republican Lieutenant Governor Kim Guadagno's campaign was dragged down by her association with deeply unpopular Governor Chris Christie.