Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

FAIRFAX, Va. — Democrat Ralph Northam handily defeated Republican Ed Gillespie in the Virginia governor race on Tuesday in a contest that was being closely watched for signs of the national electorate's mood.

With 99 percent of the vote counted, Northam had 54 percent and Gillespie had 45 percent. Gillespie conceded in a speech last night to supporters several hours after the polls closed and wished the incoming governor all the best.

In his victory speech, Northam, a doctor, made a clear reference to President Donald Trump but never mentioned him by name.

"Virginia has told us to end the divisiveness, that we will not condone hatred and bigotry," Northam said. "It’s going to take a doctor to heal our differences. And I’m here to tell you, the doctor is in!"

Northam was briefly interrupted by protesting immigration advocates who were removed from the stage by security. They appeared to be objecting to Northam's recent statement that he would sign a law banning sanctuary cities in Virginia.

Both national parties spent millions of dollars in the first major election since Trump's surprise victory last year and were closely eyeing the outcome as an early barometer of the political climate ahead of the 2018 midterm contests.

"The Democratic Party is back, my friends!" the party's national chairman, Tom Perez, said as he took the stage at Northam's victory celebration, switching between Spanish and English in his remarks.

Turnout was higher than in recent gubernatorial contests in Virginia, with more than 2.6 million votes counted by about 10 p.m. In each of the last two governor's races, fewer than 2.3 million votes were cast.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Northam, an Army veteran and a pediatric neurologist who serves as the state's lieutenant governor, had sometimes struggled to highlight his ad-ready biography as the race descended into a nasty culture war.

He got a major boost from the support of popular Gov. Terry McAuliffe, a term-limited Democrat who is handing his successor a strong economy and an electorate that told pollsters they believe the state is on the right track.

Gillespie, a former lobbyist and Republican National Committee chairman, responded to a near-loss in the GOP primary against a Trump-aligned challenger this year by taking a hard right turn on immigration and the removal of Confederate monuments.

According to NBC News exit polling data, 60 percent of Virginia voters said the monuments to Confederate leaders should be left in place, while 36 percent said that statues on government property should be removed.

Gillespie said he favored leaving the monuments but adding relevant historical details. Northam had said the monuments should be removed and put in museums, with the decision left in the hands of localities.

Trump endorsed but didn't campaign for Gillespie and attacked him shortly after his loss on Tuesday night, tweeting from South Korea that the GOP candidate "did not embrace me or what I stand for."

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! — Donald J. Trump (@realDonaldTrump) November 8, 2017

Health care was the top concern among Virginia voters, with 37 percent citing it as the most important issue to their vote, according to the NBC News exit poll.

That seemed to help Northam: A majority of people who voted for him — 57 percent — said that health care was their No. 1 concern, while Gillespie's voters turned out for a variety of reasons, including immigration and taxes.

Despite maintaining a narrow lead in the polls, Democrats headed into election night with white knuckles, still shaken by Trump's win last year. A loss for Democrats in Virginia would have been devastating.

In New Jersey, Democrat Phil Murphy trounced Republican Kim Guadagno in a landslide in the governor's race — letting the door hit Gov. Chris Christie on his way out of office as one of the least popular governors in the country.

With 98 percent of the vote in, Murphy had 56 percent of vote and Guadagno 43 percent.

Both parties expected Murphy, a former Goldman Sachs executive and Obama-era ambassador to Germany, to prevail, largely because Christie's anemic 14 percent approval rating dragged down Guadagno, his lieutenant governor.

Virginia Gov.-elect Ralph Northam walks onstage to celebrate his election at the Northam For Governor election night party at George Mason University in Fairfax, Va., Tuesday, Nov. 7, 2017. Cliff Owen / AP

Guadagno struggled throughout the campaign to escape Christie's shadow, along with lingering questions about the Bridgegate scandal, although she saw some positive movement in recent polls after adopting a sharper tone on immigration that echoed Trump.

Murphy's victory gives Democrats complete control of New Jersey government, where Christie often battled with the opposition-controlled state Legislature. That makes the state one of just seven nationwide where Democrats now control the governor's mansion and both chambers of the legislature, compared to a whopping 26 for Republicans.

In New York City, Democrat Bill de Blasio won a second term as mayor, crushing his Republican rival, Nicole Malliotakis. With 99 percent of the vote in, de Blasio had 67 percent and Malliotakis 28 percent.

In a special election in Utah, to fill the retiring Jason Chaffetz's congressional seat, Republican John Curtis defeated Democrat Kathie Allen, 58 percent to 27 percent, with 75 percent of the vote in.