FAIRFAX, Va. — Voters delivered their first forceful rebuke of President Trump and his party on Tuesday night, with Democrats exploiting Mr. Trump’s deep unpopularity to capture the governorships in Virginia and New Jersey and make significant inroads into suburban communities that once favored the Republican Party.
The Democratic Party’s crowning success of the night came in Virginia, where Lt. Gov. Ralph S. Northam, an understated physician and Army veteran, won a commanding victory for governor, overcoming a racially charged campaign by his Republican opponent and cementing Virginia’s transformation into a reliably Democratic state largely immune to Trump-style appeals.
Mr. Northam was propelled to victory over Ed Gillespie, the Republican nominee, by liberal and moderate voters who were eager to send a message to Mr. Trump in a state that rejected him in 2016. Mr. Northam led Mr. Gillespie by nearly nine percentage points with 99 percent of precincts reporting, the widest victory in decades for a Democratic candidate for governor of Virginia.
The campaign between a couple of low-key, establishment politicians was brought to life when Mr. Gillespie injected a handful of wedge issues, from immigration to Confederate iconography, into the race. But voters in Virginia’s affluent and highly educated urban centers rejected those tactics, handing Mr. Northam enormous margins in the state’s most vote-rich localities.
Addressing jubilant supporters in Northern Virginia, Mr. Northam aimed his remarks squarely at Mr. Trump and Republicans echoing his politics.
“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,” he said, adding that in this state, “It’s going to take a doctor to heal our differences.”
The Democrats’ electoral validation, though, took place well beyond the Virginia governor’s race: They wrested the governorship of New Jersey away from Republicans, swept two other statewide offices in Virginia and made gains in the Virginia State Legislature, and won a contested mayoral race in New Hampshire, according to The Associated Press.
In New Jersey, Philip D. Murphy, a former Goldman Sachs executive, won the governorship, according to The Associated Press, by a vast margin that brought an unceremonious end to Gov. Chris Christie’s tumultuous tenure.
In both Virginia and New Jersey, voters rebuffed a wave of provocative ads linking immigration and crime, hinting at the limitations of hard-edge tactics in the sort of affluent and suburban communities that are pivotal in next year’s midterm elections.
Even though Republicans in the two states mirrored Mr. Trump’s grievance-oriented politics, they kept him at arm’s length: He became the first president not to appear on behalf of candidates for governor in either state since 2001, when George W. Bush shunned the trail after the Sept. 11 attacks.
Since then, four of the five governors Virginia has elected have been Democrats. The party was also in contention late Tuesday to seize control of the state House of Delegates, an unexpected show of strength that, along with Mr. Northam’s victory, offered Democrats a stronger hand to block any Republican attempts at gerrymandering after the next census.
Representative Scott Taylor, a Republican from Virginia Beach, said he considered the Democratic sweep in Virginia a repudiation of the White House. He faulted Mr. Trump’s “divisive rhetoric” for propelling the party to defeat, and said he believed traditionally Republican-leaning voters contributed to Mr. Northam’s margin of victory.
“I do believe that this is a referendum on this administration,” Mr. Taylor said of the elections. “Democrats turned out tonight, but I’m pretty sure there were some Republicans who spoke loudly and clearly tonight as well.”
Channeling the shock of Republicans across the state, Mr. Taylor voiced disbelief at the party’s rout down ballot. “I know folks that lost tonight who were going against candidates I’d never even heard of,” he said.
Mr. Trump was quick to fault Mr. Gillespie for keeping his distance, writing on Twitter while traveling in South Korea that the Republican candidate “did not embrace me or what I stand for.”
Mr. Gillespie made no mention of Mr. Trump in his concession speech, and alluded only in passing to the explosive themes he wielded as a candidate. Ticking off issues he campaigned on, Mr. Gillespie noted his supporters were worried about “safety for themselves and their families and their businesses.”
Addressing supporters in a hotel ballroom, Mr. Gillespie tried to tack a courteous finale on to a rough-and-tumble race, offering his assistance to Mr. Northam going forward. “I wish him nothing but the best success,” Mr. Gillespie said.
Mr. Northam’s victory was a tonic to an anxious national party that has been reeling since Mr. Trump’s win last year and was demoralized by losses in special House elections in Montana and Georgia.
A native of Virginia’s rural Eastern Shore, Mr. Northam, 58, was a perhaps an unlikely vessel for the resistance-era Democratic Party. But the left overlooked the two votes he cast for George W. Bush before he entered politics, and his résumé — he is a pediatric neurologist and Gulf War veteran — proved far more appealing to the state’s broad middle than Mr. Gillespie’s background as a corporate lobbyist.
The Democrats’ success here came as Mr. Gillespie, trailing in the polls, turned to a scorched-earth campaign against Mr. Northam in the race’s final weeks. Mr. Gillespie, a fixture of his party’s establishment who had once warned against the “siren song” of anti-immigrant politics, unleashed a multimillion-dollar onslaught linking his rival to a gang with Central American ties and a convicted pedophile who had his rights restored, while also assailing Mr. Northam for wanting to remove Virginia’s Confederate statues.
The strategy appeared to help Mr. Gillespie narrow the gap in the wake of the Charlottesville protests this summer, but it was not enough to overcome the anti-Trump energy in an increasingly diverse state that has not elected a Republican to statewide office since 2009.
Mr. Gillespie, a former Republican National Committee chairman, found it difficult to balance appeals to the president’s unflagging supporters in rural Virginia while simultaneously attempting to win over Mr. Trump’s skeptics in the state’s population centers. He often would not say the president’s name, referring instead to “the administration” or last year’s Republican “ticket.”
In his concession speech, Mr. Gillespie made no mention of Mr. Trump, and declined to answer questions about the president’s criticism on Tuesday night.
Mr. Northam did not have to concern himself with any such political contortions running in a state that has backed the Democratic nominee for president in the last three elections, a striking reversal from an earlier day here when Virginia Democrats had to distinguish themselves from their more liberal national party.
Indeed, support for Mr. Northam represented a vote for continuity. Gov. Terry McAuliffe, a Democrat barred by state law from seeking re-election, is broadly popular, as are the state’s two Democratic senators, Tim Kaine and Mark Warner. Mr. McAuliffe, who was elected in 2013 during President Barack Obama’s second term, was the first person in 40 years to win a Virginia governor’s race who was in the same party as the president’s.
In New Jersey, the Democratic ticket established a decisive advantage early in the campaign season, and that lead never flagged. Mr. Murphy, a wealthy Democratic donor who served as ambassador to Germany under former Mr. Obama, ran on a message of rejecting both Mr. Trump and Mr. Christie, who is a politically toxic figure in the state. A cavalcade of major national Democrats marched through the state to back Mr. Murphy, including Mr. Obama, Hillary Clinton and Joseph R. Biden Jr.
National Republicans virtually ignored the race, viewing their nominee, Lt. Gov. Kim Guadagno, as doomed by a deeply hostile political environment and her association with Mr. Christie. In Utah’s Third Congressional District, John Curtis, the Republican nominee, emerged as the winner Tuesday night, according to The Associated Press.
After blanketing Virginia’s airwaves before the primary with an ad in which he savaged the president as “a narcissistic maniac,” Mr. Northam struck a more sober-minded tone during the general election with another widely aired commercial in which he vowed to “work with” Mr. Trump when it is in the state’s interest.
The tone of the race changed in October when Mr. Gillespie began airing an ad excoriating Mr. Northam for supporting a state measure in support of so-called sanctuary cities, which limit cooperation with federal immigration agents. The commercial featured a group of heavily tattooed men who turned out to be prisoners in a Salvadoran jail.
It was followed not long after by a series of ads focusing on Mr. Northam’s support for the restoration of rights for felons after they are released from prison; these featured a convicted child molester.
Democrats cried foul, but then only seemed to hand Mr. Gillespie a chance to express his own outrage when, in the last week of the campaign, a liberal Hispanic advocacy group aired a commercial portraying a man in a truck with a Gillespie sticker trying to drive into a group of children of color.
The group pulled the spot in the aftermath of the deadly truck attack in New York and Mr. Northam distanced himself from it, but not before it gave Republicans late fodder.