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.

His dominating performance offered a momentary catharsis for Democrats beyond the state’s borders who have been hungry to find political success this year and represented a stern warning to Republicans on the ballot next year about the peril of embracing Mr. Trump’s approach.