‘‘The people are gonna rise up. They’re not gonna take what he says and this is not fake news,’’ said Leanna Barnes, a 76-year-old from East Orange, N.J., who voted for Murphy and added she saw his victory as a message to the president.

Related Links

Virginia college student Tamia Mallory said she began paying attention to her state’s gubernatorial race when she saw tweets from Trump endorsing Gillespie.

That motivated her to examine the race and find out who was running against Gillespie, she said.

‘‘It was kind of an anti-Trump vote,’’ Mallory said.

Advertisement

Northam, the state’s lieutenant governor, repeatedly sought during long months of divisive campaigning to tie Gillespie to the president. His victory was in large part due to the surge in anti-Trump sentiment since the president took office. Democrats said they had record levels of enthusiasm heading into the race in Virginia, a swing-state and the only Southern state that Trump lost last year.

Gillespie, meanwhile, sought to keep Trump at a distance throughout the campaign but tried to rally the president’s supporters with hard-edge attack ads focused on illegal immigration and preserving Confederate statues. The strategy was criticized by Democrats and some Republicans as race baiting, but drew praise from former Trump strategist Steve Bannon and others as a canny way to win a state that voted for Hillary Clinton last year.

Trump lent limited preelection support to Gillespie with robocalls and tweets.

In one call, Trump said Gillespie shared his views on immigration and crime and would help ‘‘Make America Great Again.’’ Trump also said Northam would be a ‘‘total disaster’’ for Virginia.

But after Tuesday’s loss, Trump suggested that Gillespie hurt himself by not more closely aligning himself with the president.

Advertisement

‘‘Ed Gillespie worked hard but did not embrace me or what I stand for,’’ Trump said in a tweet after Northam won. He also pointed out that Republicans have won every special election to the US House since he was elected.

Ed Gillespie worked hard but did not embrace me or what I stand for. 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’s victory is a blow to Republicans, who were hoping that Gillespie could provide a possible roadmap for moderate Republicans to follow in next year’s midterm elections. Several Republicans have revealed plans to retire next year instead of seeking re-election.

Gillespie struck a humble tone in his concession speech as he offered support to Northam.

Democrats were gleeful at Northam’s victory party. US Representative Gerry Connolly called Northam the ‘‘perfect antidote’’ to the president. ‘‘This is a comprehensive victory from the statehouse to the courthouse. Thank you, President Trump,’’ Connolly said.

The Democratic victories are another sign of Virginia’s shift toward a more liberal electorate.

Democrats have won every statewide election since 2009 and now have won four out of the last five gubernatorial contests.

Northam banked heavily during the campaign on his near-perfect political resume and tried to cast himself as the low-key doctor with a strong Southern drawl as the healer to Trump’s divisiveness.

A pediatric neurologist and Army doctor, Northam made health care reform a centerpiece of his political career and current campaign, winning key allies along the way.

In other elections across the country:

■ In addition to keeping the governorship, Democrats nearly wiped out Republicans’ overwhelming majority in the Virginia House of Delegates. One of the Democratic newcomers will be Danica Roem, a transgender woman who unseated Bob Marshall, one of the chamber’s longest serving and most conservative members.

■ New York Mayor Bill de Blasio easily won a second term, capitalizing on economic growth, low crime, and a weakened Republican Party in a race he turned into a referendum on progressive government.

The incumbent Democrat handily defeated Republican Nicole Malliotakis, a member of the state assembly, and a smattering of independent and third-party candidates.

Material from The New York Times and The Washington Post was used in this report.