Democrat Ralph Northam won a bitter race for Virginia governor on Tuesday, dealing a political setback to President Donald Trump by beating a Republican who embraced 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 hitting the soft-spoken Democrat on divisive issues such as immigration, gang crime and Confederate statues.
Trump had endorsed Gillespie but not campaigned with him. The Republican president 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 the Virginia Republican.
“Ed Gillespie worked hard but did not embrace me or what I stand for,” he said. “With the economy doing record numbers, we will continue to win, even bigger than before!”
The Northam victory, in a state that Democrat Hillary Clinton won by 5 percentage points in the 2016 presidential election, also was 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 exit polls in Virginia showed that one-third of the voters went to the polls to oppose Trump, and 17 percent went to support him.
Democrat elected New Jersey governor
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.
In Virginia, Democrats had worried that if Gillespie won, Republicans would see it as a green light to emphasize 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.
Democrats were also were gaining seats in the Virginia House of Delegates. Democrat Danica Roem beat a 25-year Republican incumbent to become the first transgender person to win a state legislative race.
Voters in Arlington County – a 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.
Lee Hernandez, who works in finance, voted for Gillespie because he found the Republican’s economic message persuasive. Hernandez said he found Northam’s campaign message “a really big turnoff” because of the emphasis on keeping Virginia in Democratic hands.
In local races across the country, Democratic Mayors Bill de Blasio in New York and Marty Walsh in Boston were expected to cruise to re-election, while voters were picking mayors in Detroit, Atlanta, Seattle and Charlotte, North Carolina.
This article originally appeared on Fortune.