Possibly the most intriguing election of 2017 just got a lot more intriguing.

With Virginia Gov. Terry McAuliffe (D) term-limited, Democrats are scrambling to hold onto the Virginia governor's mansion this November. It's expected to be a battle, but they were cruising to an easy nomination of McAuliffe's hand-picked successor, Lt. Gov. Ralph Northam (D).

Or at least, they were. Another Democrat with ambitions of higher office threw a wrench into those carefully laid  plans Thursday. Former U.S. representative Tom Perriello (D-Va.), a former State Department official who has ties to President Obama, announced Thursday morning that he's running for governor.

His announcement surprised top Virginia Democrats in a bad way, The Post's Laura Vozzella explains. They  have spent more than a year lining up behind Northam, only to have a credible challenger jump in just five months before their June primary.

Democrats recognize there's little room for error in this race. Keeping Virginia's governorship is a crucial part of their national strategy to try to take back control of state legislatures — and even Congress. The next Virginia governor will have veto power over new electoral maps the Republican-controlled legislature is going to draw after the 2020 Census.

Virginia Democrats are hoping a confluence of history, demographic trends and state politics will help them win.

For the past two decades, the party out of the White House has won the Virginia governor's race (with the exception of McAuliffe's win in 2013). And the once-conservative state is trending more blue, thanks to a confluence of more college-educated, younger and minority voters moving into the state. Nonpartisan handicapper Louis Jacobson notes that Hillary Clinton actually won Virginia in 2016 by more than President Obama won it four years earlier.

It's unclear just how much Perriello will actually shake up the Democratic primary. Pretty much the entire state's Democratic leadership has already endorsed Northam for the job, signaling they're willing to spend time, money and star power to help him get elected. Two of the state's highest-profile Democrats, the governor and Sen. Tim Kaine (D-Va.), reaffirmed their support for Northam.

“He’s got a better chance of flapping his wings and flying to the moon than getting within 50 points of that nomination,” state Senate Minority Leader Richard L. Saslaw told Vozzella.

To that point, Perriello would probably need to peel off some of those high-profile supporters. Democrats watching the race aren't convinced the one-term congressman can do that, much less raise millions in what's expected to be one of the most competitive governor's races in the country. (Perriello won in a red-leaning Virginia district in 2008 but lost his seat two years later.)

But the quality of the candidate could play a bigger role than who supports him, Jacobson said.

Virginia's state and local elections are held in an off-year, which means the candidates will have a much bigger spotlight on them than if, say, there were also a presidential race to focus on. Despite the fact he's only spent one term in Congress, Jacobson said, “Perriello has gotten pretty good reviews.”

What makes Perriello's last-minute entry into the race even more maddening for establishment Virginia Democrats is that they were on track to avoid what Republicans cannot: a competitive primary.

Virginia Republicans decided to open up their nominating system from a party-run convention to a state-run primary, which in turn opens up voting from just hardcore activists to all state voters. There are no fewer than three viable candidates who think they can take advantage of the new, more open nominating system.

Former GOP strategist Ed Gillespie appears to be the front-runner. (He very nearly unseated Sen. Mark R. Warner (D) in 2014.) But he'll have to face down state Sen. Frank Wagner, who has strong support in some of the more conservative regions of the state.

Gillespie is also being challenged from the right by the colorful Corey Stewart, who chairs the Prince William Board of County Supervisors and was the former state chair of Donald Trump's presidential campaign (until he got fired for protesting outside the Republican Party headquarters). Stewart knows how to draw a headline: The other day, his campaign offered to give away an AR-15 rifle to “one lucky supporter." More outsiders could enter the race at the last minute, too.

Speaking of outsiders, the Virginia's governor's race is one of the only competitive races this year (Democrats are favored to win term-limited New Jersey Gov. Chris Christie's (R) seat.) And since Virginia is the wild west of state campaign finance laws — there are literally no limits on how much you can donate to a state candidate — both sides expect outside groups to dump millions to try to influence the race.

Either way, there are no sure bets in this race: A December Quinnipiac poll of Gillespie and Northam suggests this all-important governor's race is indeed going to be a very competitive one.