Gubernatorial candidates Lt. Gov. Ralph Northam, left, and Ed Gillespie shake hands prior to debate in Washington, Tuesday, Sept. 19, 2017. (Bonnie Jo Mount/AP)

President Trump injected himself into Virginia’s governor’s race late Thursday, tweeting an endorsement of Republican Ed Gillespie and accusing the Democratic contender of supporting violent gangs.

“Ralph Northam,who is running for Governor of Virginia,is fighting for the violent MS-13 killer gangs & sanctuary cities. Vote Ed Gillespie!” Trump tweeted to his 40 million followers at 9:58 p.m.

The tweet roils a race where most public polls have consistently shown Northam with a lead over Gillespie. A Washington Post-Schar School poll released Thursday showed Northam with a 13-point edge, while nearly six in 10 voters disapproved of Trump.

While Trump’s tweet may excite his supporters in Virginia, the president’s decision to wade into the race for governor poses risks for Gillespie. Trump remains deeply unpopular in Virginia, the only Southern state won by Hillary Clinton last fall.

Northam, the state’s sitting lieutenant governor and a pediatrician who has called the Trump a “narcissistic maniac,” seized on the tweet to fundraise. He responded to Trump’s volley with his own tweet linking to a donation page.

Gillespie has struggled throughout the race to figure out how to run as a Republican in the Trump era, trying to simultaneously appeal to Trump voters without alienating moderate Republicans and independents he needs to win in the purple state. He remained silent about Trump’s tweet Thursday night. It is unclear if the candidate asked for the president’s endorsement.

On a conference call with reporters Friday morning, Gillespie said he first saw the tweet on his I-phone Thursday night and thought, “one of my ads must be running in D.C.” He said he saw no reason to say anything about it. “He has 40 million followers,” Gillespie said, referring to Trump’s Twitter account. “I didn’t need to retweet.”

Gillespie would not say if his campaign sought the endorsement. But he and other Republican leaders tried to downplay it Friday morning. “It’s not suprising that a Republican president would endorse a Republican candidate,” Gilllespie told reporters.

He declined to say whether Trump will campaign for him in the final four weeks of the race.

Virginia is holding the nation’s marquee statewide contest this year. The race to succeed Gov. Terry McAuliffe (D) is widely seen as a hint of what’s to come in next year’s mid-terms.

Gillespie, a longtime GOP operative and establishment figure who worked as a White House aide to former President George W. Bush, nearly lost the Republican nomination in June to Corey A. Stewart, a bombastic campaigner who gave away an assault rifle, attacked illegal immigration and fashioned himself in the Trump mold.

White House political advisors urged the Gillespie campaign to hire some of Trump’s strategists and go hard after Trump voters during the general election.

For most of the campaign, though, the contest for Virginia governor had been applauded by observers for its relative civility.

But in late September, Gillespie rolled out four TV ads and mailings that sought to tie Northam to the MS-13 gangs - a claim that has been labeled “misleading” by the non-partisan FactCheck.org and racist by immigration advocates. The decision to highlight illegal immigration late in the campaign is a bit of a gamble in a state with a growing immigrant population and where voters have expressed far greater concern about health care, the economy and education, according to the new Washington Post-Schar School poll.

The ads are a variation on a single theme and feature frightening images of tattooed gang members or an ominous, dark, hooded figure holding up a baseball bat as the MS-13 motto “Kill, Rape, Control” flashes on the screen. The narrator warns of violent crime linked to the street gang in Virginia — and accuses Northam of putting Virginia families at risk.

It refers to a tie-breaking vote cast in January by Northam in the state Senate against a GOP bill that would have banned sanctuary cities in Virginia. It was a pre-emptive measure: Virginia does not have sanctuary cities, a fact that Gillespie has acknowledged.

But the ads say that Northam’s actions allowed “dangerous illegal immigrants back on the street.”

Trump’s tweet used the same line of attack.

Democrats responded to Trump’s endorsement with condemnation.

“They both want to cut funding to education, roll back healthcare, and divide Virginians for political gains,” said David Turner, a spokesman for Northam. “Looks like Ed Gillespie’s ads are reaching his target audience--Donald Trump.”

The Democratic Governors Association said the endorsement should come as no surprise.

“The facts are clear: Ed Gillespie will not stand up to Donald Trump on policies that harm Virginians,” said Jared Leopold, a spokesman for the Democratic Governors Association. “Now that Gillespie has Trump’s official endorsement, we look forward to seeing them proudly campaign together this month.”

It’s unclear if Trump will campaign for Gillespie, who has said he would welcome the president’s help. Trump stumped in Virginia at least 10 times during his presidential campaign, and has business connections in the commonwealth with a golf course and winery branded with his name.

Jenna Johnson contributed to this report.