Mr. Trump has tweeted twice about the Virginia race, including on Saturday night, when he wrote that “Democrats in the Southwest part of Virginia have been abandoned by their Party,” as Mr. Pence was on the way to the region.

Yet whether Mr. Trump sets foot here or not, his success at motivating voters with culturally and racially tinged appeals has worn off on Mr. Gillespie. Once one of the loudest voices in his party for an inclusive message, Mr. Gillespie is now assailing Mr. Northam over the Democrat’s opposition to a state measure that would have banned “sanctuary cities” and targeting him for supporting the removal of the state’s many Confederate statues.

The Republican chafes at questions over whether he is adopting a Trumpian message and forgoing his own advice in 2006 that Republicans should resist the “siren song” of anti-immigration rhetoric, insisting he is running as “who I am and what I believe in.”

“The great thing about a governor’s race in Virginia is the people who vote in it are focused on roads and schools and jobs and the opioid and heroin epidemic,” Mr. Gillespie said.

But his advertising reflects what he thinks will actually move the electorate: He is spending the bulk of his money on commercials focused on the statues, which make no mention of his view that the South was “on the wrong side of history,” and illegal immigrants. One of his immigration ads features amply tattooed Salvadoran prisoners meant to be members of the menacing gang MS-13, a target of the president’s.

Asked if he still supported a pathway to legal status for illegal immigrants, which he once vocally championed, Mr. Gillespie unenthusiastically confirmed that he did, deflating his answer by noting that “the debate is 10 years old from my perspective.” (He did more readily note that he supported “accommodating those who were brought here as children illegally,” the so-called Dreamers.)

Mr. Northam, for his part, also does not quite seem sure how he should handle Mr. Trump. Appearing earlier this month at a Falls Church shopping center that is a hub for the Vietnamese community, he alluded to “bigotry” in last year’s campaign without mentioning Mr. Trump by name. But his remarks were tame compared to those by the state legislator who introduced him and called Mr. Trump’s election “the world’s largest nightmare” and scorned the president as a “draft dodger.”