RICHMOND, Va. (AP) — Seizing his party's first major Trump-era victory, Democrat Ralph Northam beat back a charge from Republican Ed Gillespie in the race for Virginia governor, a bruising election that tested the power of President Donald Trump's fiery nationalism against the energy of the Trump resistance.

In Virginia, as in several contests across America on Tuesday, the Trump resistance won. And it wasn't close.

Northam, a pediatric neurologist and Army veteran, defeated longtime Republican operative Gillespie in the hard-fought contest. "I'm here to let you know that the doctor is in," a smiling Northam told supporters gathered in suburban Washington, D.C., for his victory speech. "As long as I'm governor, I will work hard to make sure we're inclusive."

He added, "Virginia has told us to end the divisiveness, that we do not condone hatred and bigotry and to end the politics that have torn this country apart."

Northam's victory set off overnight recriminations and finger-pointing among Trump's hardcore supporters. The pro-Trump website Breitbart News, which had earlier praised Gillespie as a "culture warrior," derided him as a "Republican swamp thing." Jerry Falwell Jr., president of Liberty University, said Northern Virginia's voter-rich liberal suburbs should be annexed by the District of Columbia, "to return the governance of (Virginia) to Virginians."

Democrats also scored victories in the race for New Jersey governor and in Maine, where voters slapped the state's Republican governor, a Trump ally, by backing a measure to expand Medicaid coverage under former President Barack Obama's health care law. The Democratic mayors of New York and Boston, both vocal Trump critics, also won re-election easily.

And Virginia voters elected the state's first openly-transgender state representative, among more than a dozen state legislative pickups for Democrats.The resounding victories marked the GOP's most significant day of defeat in the young Trump presidency and a rebuke to the president himself as his party eyes a suddenly more threatening midterm election season next year.

The Democratic gubernatorial victories in Virginia and New Jersey prompted congratulations from Obama, who tweeted Wednesday morning, "This is what happens when the people vote." Obama also congratulated "all the victors in state legislative, county and mayors' races."

"The Democratic Party is back, my friends," said Democratic National Committee Chairman Tom Perez.

Perez said the key to his party's success in Tueday's elections was fielding good candidates and thorough organizing efforts."Organizing matters," Perez told MSNBC's "Morning Joe." ''This was the most extensive, coordinated ground game in Virginia history, more extensive than any presidential ... Terry McAuliffe did a spectacular job four years ago, and they did that much more."

Trump immediately tried to distance himself from the loss.

"Ed Gillespie worked hard but did not embrace me or what I stand for," Trump tweeted Tuesday night as he toured Asia, noting that the GOP won a handful of special elections earlier in the year. "With the economy doing record numbers, we will continue to win, even bigger than before!"

Despite the criticism, Gillespie did, in more ways than one, embrace what Trump stands for, even if he didn't welcome Trump into the state to rally voters on his behalf.

The Republican president played a marginal role in Virginia, largely because Republicans on the ground did not want him there, a state he lost last fall, as his approval ratings hover near record lows. The White House instead dispatched Vice President Mike Pence to help Gillespie, although Trump promised Gillespie would "make America great again" in a recorded phone message that went to voters on the election's final day.

Gillespie, a former aide to President George W. Bush and GOP presidential nominee Mitt Romney, largely reinvented himself as Election Day neared by adopting many of Trump's racially-tinged nationalist positions. Gillespie warned of the dangers of the Hispanic street gang, MS-13, and highlighted its motto, "Kill, Rape, Control" in a television ad. The New Jersey native vowed to protect Confederate monuments. And he condemned the national anthem protests by NFL players, the vast majority of them black.

Liberal activists cheered their successes as evidence of the anti-Trump energy on the ground nationwide they have long insisted was real, despite poor results in special elections in deep-red Montana, Georgia and South Carolina.

"This is the first fair fight we've had. The special elections that we've had so far have been incredibly slanted to the conservative side," said Ezra Levin, co-founder of the liberal group Indivisible, which had hundreds of volunteers and a handful of paid staff on the ground in Virginia. "There is a wave building. And 2018 is just around the corner."

New Jersey Democratic Sen. Cory Booker, among several Democrats weighing a presidential bid in 2020, cast his party's gubernatorial victories in New Jersey and Virginia as "the very first statewide rebuttal of the Trump administration."