WASHINGTON (Reuters) - Democrat Ralph Northam won a bitter race for Virginia governor on Tuesday, dealing a setback to President Donald Trump with a decisive victory over a Republican who had adopted some of the president’s combative tactics and issues.

Northam, the state’s lieutenant governor, overcame a barrage of attack ads by Republican Ed Gillespie that hit the soft-spoken Democrat on divisive issues such as immigration, gang crime and Confederate statues.

Trump, who endorsed Gillespie but did not campaign with him, had taken a break from his Asia trip to send tweets and record messages on Tuesday supporting the former chairman of the Republican National Committee.

But after the outcome, Trump quickly distanced himself from Gillespie.

“Ed Gillespie worked hard but did not embrace me or what I stand for,” Trump tweeted. “With the economy doing record numbers, we will continue to win, even bigger than before!”

At his victory party, Northam told supporters the sweeping Democratic win in Virginia sent a message to the country.

“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 said.

The Virginia race highlighted a slate of state and local elections that also included a governor’s race in New Jersey, where Democrat Phil Murphy, a former investment banker and ambassador to Germany, defeated Republican Kim Guadagno for the right to succeed Republican Chris Christie.

Murphy had promised to be a check on Trump in Democratic-leaning New Jersey. Guadagno, the lieutenant governor, was hampered by her association with the unpopular Christie.

Slideshow ( 26 images )

BOOST FOR DEMOCRATS

Murphy’s win and the Northam victory in Virginia, a state Democrat Hillary Clinton won by 5 percentage points in the 2016 presidential election, provided a much-needed boost for national Democrats who were desperate to turn grassroots resistance to Trump into election victories.

Democrats had already lost four special congressional elections earlier this year.

But a strong turnout in the Democratic-leaning northern Virginia suburbs of Washington helped propel Northam, who in the end won relatively easily. With nearly all precincts reporting, he led by a 53 percent to 45 percent margin.

Exit polls in Virginia showed that one-third of the voters went to the polls to oppose Trump, and only 17 percent went to support him.

Democrats also swept the other top statewide Virginia races, winning the offices of lieutenant governor and attorney general, and gained seats in the Virginia House of Delegates. Democrat Danica Roem beat a long-time Republican incumbent to become the first transgender person to win a state legislative race.

“This is a comprehensive political victory from statehouse to courthouse. Thank you Donald Trump!” Democratic U.S. Representative Gerald Connolly of Virginia told Northam’s supporters at a victory party in northern Virginia.

In Virginia, Democrats had worried that if Gillespie won, Republicans would see it as a green light to emphasize divisive cultural issues in their campaigns for next year’s elections, when all 435 seats in the U.S. House of Representatives and 33 of the U.S. Senate’s 100 seats come up for election. Republicans now control both chambers.

Slideshow ( 26 images )

Gillespie, speaking to crestfallen supporters in Richmond, Virginia, said he had run a “very policy-focused campaign.”

But voters in Arlington County - a suburban Democratic stronghold bordering Washington - said national politics were important to their votes.

“Trump talks about draining the swamp, but Gillespie kind of is the swamp,” said Nick Peacemaker, who works in marketing and considered himself a Republican until Trump won the party’s presidential nomination.

Peacemaker said Gillespie seemed to shift closer to Trump’s policies after securing the Republican gubernatorial nomination.

In local races across the country, Democratic Mayor Bill de Blasio in New York and Marty Walsh in Boston both easily won re-election. Voters were also picking mayors in Detroit, Atlanta, Seattle and Charlotte, North Carolina.