The Virginia Democratic gubernatorial primary is taking an unusually sharp turn to the left in a Southern state known for centrist Democrats.

Lt. Gov. Ralph Northam and his rival for the party’s nomination, former congressman Tom Perriello, are shoring up their progressive credentials with support for liberal causes and denouncements of President Trump.

It’s a reflection of a changing political landscape in a state where Democrats are increasingly comfortable running as progressives. Although the state legislature is controlled by Republicans, all five statewide offices are held by Democrats.

The state also voted blue in the past three presidential contests, including in November when Virginia was the only Southern state that Hillary ­Clinton won.

Virginia’s gubernatorial race, one of just two across the country this year, provides the first test of electoral politics after the polarizing election of Trump.

Northam, who was once courted by Republicans to switch parties, is emphasizing his support for abortion rights and gun control in a state where Democrats once tread carefully on such issues. Last week, he backed marijuana decriminalization as a racial justice issue.

Since his surprising entry into the race in January, Perriello has been pitching himself as a populist capable of turning out voters. He speaks the language of liberal activists, dropping terms such as “intersectionality” and “structural racism” in speeches. And he has positioned himself as an environmentalist, breaking from Gov. Terry McAuliffe (D) and Northam by opposing two planned natural gas pipelines in the state.

“This is really sort of unchartered territory for Democrats,” said longtime Virginia political analyst Bob Holsworth, noting that most nomination contests have been uncontested.

“A competition that focuses on the progressive wing of the party is not necessarily where they have traditionally been.”

Allies of Northam, who expected a clear path to the nomination, are increasingly seeing Perriello’s candidacy as a threat. Northam’s campaign last week challenged Perriello’s progressive bona fides, saying Perriello’s “boldness vanished” at key moments during his term in Congress.

“I’ve always from the start fought for women’s access to reproductive health care. My opponent hasn’t,” Northam said in an interview with The Post on Wednesday. “I have never been one, despite being from a very conservative area of Virginia, that puts my finger up to see which way the political winds are blowing.”

He was referring to Perriello’s voting record while representing a conservative district in Congress, including his support for an unsuccessful amendment to the Affordable Care Act in 2009 that would have prevented insurance plans covering abortions from receiving public subsidies. The day after he launched his gubernatorial campaign, Perriello penned a lengthy post on Facebook apologizing for the vote and defending abortion rights.

As a member of Congress, Perriello also opposed the assault weapons ban and was endorsed by the National Rifle Association, a group he called the “epitome of people-powered politics.” But a month ago, Perriello ripped into the NRA, calling it a “nut-job extremist organization.”

In Congress, Perriello joined a bipartisan effort within the Virginia delegation to allow oil and gas drilling off the state’s coast. At a campaign appearance this month, Perriello said he now is “very skeptical” about offshore drilling.

“You don’t do a mea culpa on three issues like that,” said Senate Minority Leader Richard L. Saslaw (D-Fairfax), who backs Northam. “He talks like Bernie Sanders, but he votes like Ted Cruz and Paul Ryan.”

Perriello says the criticism will fall flat with voters, and likens it to cherry-picking votes that don’t reflect his full record as a politician or progressive advocate.

“It is not enough to check the box on a set of progressive issues,” Perriello said in an interview Wednesday. “People want to see you have a passion about this, and devoted a lifetime to fighting about these issues.”

On the campaign trail, he said he was proud to vote for the Affordable Care Act, even if it meant losing his 2010 reelection, as well as measures to combat climate change. After his loss, Perriello led the lobbying arm of the Center for American Progress, a liberal Washington think tank, where he argued for gun control and abortion access.

Some of Perriello’s most liberal supporters say they’re willing to forgive his past stances, as they did when President Barack Obama opposed same-sex marriage and Sen. Bernie Sanders (I-Vt.) supported gun rights.

“It’s foolish for progressives to say such-and-such candidate took the wrong vote seven years ago,” said Jonathan Sokolow, a 57-year-old Reston resident who supported Sanders. “Perriello is willing to get out and fight for progressive issues at this point, and that’s what’s most important to me.”

Sokolow, like other activists, has been suspicious of Northam for siding with Republicans early in his state Senate career on budget issues and judicial appointments, to the point where they unsuccessfully asked him to switch parties. He’s also wary of Northam campaigning for lieutenant governor as a fiscally conservative moderate.

Northam stands by those labels on budget matters, but says he has never wavered on social issues such as abortion access, gun restrictions and LGBT equality.

“Those are all things that are very, very important to progressives — to Democrats in Virginia,” Northam said.

Republicans are cheering on the contested Democratic primary — predicting that the eventual nominee will be pushed too far to the left to win what usually is a low-turnout general election in an off year. Party officials recently shared a mock boxing promotional poster on Twitter featuring the Democratic primary and promising “more left turns than a 600 mile NASCAR race!”

“Virginia is a purple state,” said John Whitbeck, chairman of the Virginia Republican Party. “They are doing themselves a real disservice.”

But some political analysts say a liberal agenda in voter-rich urban areas such as Northern Virginia can be a winning strategy in the state.

U.S. Sen. Mark R. Warner (D) experienced the changing landscape when he coasted to the governor’s mansion in 2001 with help from swaths of conservative southern and southwest Virginia, then narrowly won his 2014 Senate reelection after losing those rural counties while expanding support in the Washington suburbs.

Those urban centers also fueled McAuliffe’s 2013 victory after a campaign in which he emphasized support for abortion rights and gun control.

“The strategy for winning Virginia as a Democrat 10 years ago is quite different than the strategy for winning in Virginia today,” said Stephen Farnsworth, a political-science professor at the University of Mary Washington. “A moderate centrist message is not the kind of exciting message that is most effective.”

Neither Perriello, raised in a small town outside Charlottesville, nor Northam, who speaks with the Southern drawl of his native Eastern Shore, have written off rural voters. They both plan to address economic inequality with them.

“People aren’t as interested now where you fall right versus left rather than whether you are helping them move up or down the economic ladder,” said Perriello, echoing similar comments made by Northam.

Perriello has been barnstorming the state since he joined the race. He visited an abortion clinic in Falls Church, held town halls in communities where a gas pipeline is set to be built and joined protests of Trump’s entry ban at Dulles International Airport.

Northam has been tethered to Richmond, where he must preside over the state Senate during its legislative session until it ends Feb. 25. But he has used that perch to join protests against defunding Planned Parenthood, back driver’s licenses for undocumented immigrants and praise same-sex marriage on Valentine’s Day.

Democrats say the competing appeals are good for the party and will fire up more voters ahead of November.

“(Democrats) are no longer in that straitjacket where they had to be extraordinarily cautious on those issues,” said U.S. Rep. Gerald E. Connolly (D), the only congressman who hasn’t endorsed in the governor’s race. “It’s safe to go back in the water and address those issues as a Democrat from a center-left point of view — and not permanently damage our prospects.”

Gregory S. Schneider contributed to this report.