Virginia Democratic gubernatorial candidate Tom Perriello visits the Loudoun County mosque in response to the courts blocking President Trump's muslim ban in Sterling, VA on March 17, 2017. (Photo by Linda Davidson/The Washington Post)

For Virginia Democrat Tom Perriello, the road to the governor’s mansion in Richmond includes pitstops in D.C., New York and California.

Perriello, a former congressman and diplomat under the Obama administration, has been courting Democratic party leaders, donors and progressives around the country in his primary fight against Lt. Gov. Ralph Northam.

On Tuesday, Perriello got his biggest endorsement yet — from Sen. Bernie Sanders (I-Vt.) — and with it, the hope that he can tap into Sanders’s national network for fundraising and volunteers. Sanders and Perriello are scheduled to campaign together on Thursday at George Mason University in Fairfax County.

The primary race is shaping up to be a contest of sorts between national Democrats against Virginia Democrats, who have lined up solidly behind Northam after he spent years building a deep and broad network of loyalists across the state.

Out-of-office since 2011 and most recently a State Department envoy in Africa, Perriello has spent recent weeks raising his national profile. He’s made two appearances on MSNBC, has been the subject of profiles by FiveThirtyEight and Yahoo and was interviewed for podcasts by the Huffington Post and New Republic, calling for Democrats to embrace progressive values as a way of resisting President Trump.

Sen. Bernie Sanders, I-Vt., addresses an audience during a rally Friday, March 31, 2017, in Boston. Sanders and Sen. Elizabeth Warren, D-Mass., made a joint appearance at the evening rally in Boston as liberals continue to mobilize against the agenda of Republican President Donald Trump. (AP Photo/Steven Senne)

The Virginia gubernatorial race is attracting intense national interest as one of just two governor’s races in the country this year and an early test of how voters are responding to Trump.

Political observers say Perriello had to turn to a national base as a late entrant in a race where his rival already locked up support from local officials and donors. And they say it makes sense to nationalize a race that’s shaping up as a referendum on the Trump administration.

“Perriello is doing exactly what he needs to do to mount a competitive struggle for this nomination,” said Stephen Farnsworth, a political-science professor at the University of Mary Washington. “An outsider strategy is really the only way any challenger could have gone . . . Virginia politics is increasingly becoming nationalized.”

That’s not to say Perriello is ignoring voters at home.

Like Northam, he’s been barnstorming the state, denouncing Trump and arguing for a $15 minimum wage and reduced higher education costs.

It remains to be seen whether Perriello can parlay national interest into votes.

A recent poll found Perriello rising to a tie with Northam, though nearly half of Democratic-leaning voters in that survey were still undecided.

Republicans say Perriello is making himself unelectable in a purple state by courting favor from “far-left” politicians who turn off the state’s rural and moderate voters.

“This is a huge gamble on Tom Perriello’s part with Virginia voters,” said John Whitbeck, chairman of the Republican Party of Virginia. “It may work in Arlington and Alexandria, but it’s not going to work in Bristol, in Washington County, in the Shenandoah Valley. It’s just so out of touch and in the bubble.”

Jennifer Duffy, who monitors gubernatorial races for the nonpartisan Cook Political Report, says endorsements may not sway votes — but they do lend legitimacy to Perriello’s campaign.

“Northam locked up a lot of the money in Virginia, and there is a really powerful progressive national fundraising network that can be tapped into,” Duffy said. “They need money to be competitive, and they are not going to find it at home.”

Northam had $2.5 million available heading into this year; Perriello’s first campaign finance report is due by April 17.

Perriello’s first round of fundraising included stops in New York and San Francisco.

Perriello’s campaign pitches him as a candidate who appeals to both wings of the Democratic Party, noting endorsements from Sanders as well as 30 former alumni of the Obama administration, including Barack Obama’s 2008 campaign manager, David Plouffe, and top Clinton campaign aides John Podesta and Neera Tanden, who worked with Perriello at the Center for American Progress.

Northam’s campaign counters that community leaders and elected officials from Virginia, who understand the commonwealth, its issues and its voters, have lined up behind the lieutenant governor.

“Virginia Democrats who have worked with Ralph are supporting him because he has been a progressive leader in Virginia,” spokesman David Turner said in a statement after Sanders’s endorsement.

Figures well known among progressive activists, if not Virginia voters, are also praising Perriello.

Former congressman Henry A. Waxman (D-Calif.), who is popular among environmentalists, on Tuesday penned an op-ed for the Huffington Post calling Perriello the “future of the Democratic Party in Virginia and beyond” and praising his record on climate change.

Zephyr Teachout, a good government advocate who unsuccessfully challenged New York Gov. Andrew M. Cuomo, tweeted her support for Perriello last week, saying he was the “populist, anti-monopolist, pro-union, anti-corruption against ultimate insider.” She followed up with a fundraising appeal to 150,000 people on the email list for her organization, the Anti-Corruption League, where she deemed the gubernatorial primary the most important race in the country.

In an interview, Teachout said Perriello caught her attention after friends mentioned how he had been railing against consolidated food and energy production and has pledged not to take contributions from Dominion, Virginia’s utility giant and the state’s largest political donor.

Pressed about why she called Northam “the ultimate insider,” Teachout said she was referring to his support from elected officials in Virginia.

Northam campaign aides and Republican operatives poked fun at Perriello last week for agreeing to write an op-ed for the Los Angeles Times, instead of a Virginia newspaper, about losing his congressional seat in 2010 after voting for the Affordable Care Act. That article later trended on the Reddit politics page.

Among the local Virginians who took note of the opinion piece was Ian Ware, 19, a sophomore at the University of Virginia.

“It’s awesome he’s nationalizing this race because one of the issues in Virginia is you have really entrenched party lines where people are always going to support the traditional party candidate,” said Ware, an environmental activist. “You have to get outside that institutional bubble if you want more exposure and support.”

Incumbent Gov. Terry McAuliffe (D), who backs Northam, is constitutionally barred from serving consecutive terms. The winner of the Democratic primary will take on the winner of the three-way GOP contest between former Republican National Committee chairman Ed Gillespie, state Sen. Frank Wagner (Virginia Beach) and Corey Stewart, the chairman of the Prince William Board of County Supervisors.