Of the many lessons to draw from Virginia’s unusual gubernatorial election Tuesday, one of the most surprising was Democrat Terry McAuliffe’s victory even while supporting such liberal policies as same-sex marriage and stricter gun controls.

That’s an enormous change in Virginia just within the past decade, and it illustrates how a purple swing state is acquiring a more bluish tinge.

The election broke with political precedent in the Old Dominion in multiple ways: for its negativity, its focus on ethical controversies and the large role played at the end by national issues including the federal government shutdown and President Obama’s health-care overhaul.

The shutdown gave McAuliffe a boost in October in his race against Republican Ken Cuccinelli II. Voters blamed tea party Republicans for the gridlock in Washington, and Cuccinelli has been a hero to the GOP’s hard-core, anti-government wing.

But Cuccinelli gained steam in the campaign’s closing days by linking McAuliffe to the well-publicized problems in the health-care program’s rollout. That apparently cut sharply into the Democrat’s margin of victory, compared with the polls’ predictions.

When Terry McAuliffe was elected governor of Virginia Tuesday night, it was the latest indication the state might slightly favor Democrats. (The Washington Post)

Stepping back from the ebbs and flows of the past few weeks, an overall message of the campaign was a shift to the left on such issues as guns and gays.

In previous campaigns for governor, Democratic candidates took care not to offend the National Rifle Association. But McAuliffe’s supporters ran television ads criticizing Cuccinelli for siding with the NRA by opposing universal background checks for gun purchases.

Seven years ago, Virginians voted by a landslide to amend the state constitution to ban same-sex marriage and civil unions. But McAuliffe painted Cuccinelli as behind the times for battling against equal rights for gays.

“It is a real sea change in the electorate here,” said George Mason University political scientist Mark Rozell. “The old conventional wisdom in Virginia politics was that for a Democrat to win statewide, you had to run well to the right of the national party. That’s no longer true.”

The changes result partly from national changes in attitudes and partly from shifting demographics that have transformed Virginia from a conservative Southern state to a centrist Middle Atlantic one.

It was clear from Obama’s victories in the state in 2008 and 2012 that such an evolution had occurred in presidential election years. Tuesday’s result confirms that it has taken place as well in low-turnout, off-year races.

For Republicans, the lesson’s flip side is that it’s extremely difficult, and perhaps impossible, to win the governorship with candidates like Cuccinelli, who are champions of the party’s most conservative wing. As I anticipated in my column Thursday, voters rejected tea party and religious right principles — albeit by a smaller margin than expected.

The result will be a tug of war among Virginia Republicans over whether to change their political profile and nominating process, lest they repeat this year’s setback.

Here are three other lessons from Election Day Virginia, 2013:

Flawed candidates yield negative campaigns. Both McAuliffe and Cuccinelli had significant shortcomings from the start, and each tried to win principally by tearing down the other.

McAuliffe has no experience in elective office and a cloudy record in business and fundraising. Cuccinelli’s aggressive activism has made him controversial for years.

As negative ads filled the airwaves, unusually large numbers of voters viewed both candidates with distaste. Cuccinelli lost largely because he was disliked more, particularly because of his conservative positions on social issues such as abortion.

“Republicans used to win on being the party of personal liberty. Now, among women and young people, that perception is entirely reversed. They are the party of government restriction,” said Bob Holsworth, a longtime Richmond political commentator.

Ethics has become a Virginia issue. For the first time since the 1994 U.S. Senate race between Chuck Robb (D) and Oliver North (R), scandals were front and center in a Virginia election.

It started with the controversy over a businessman’s gifts to Gov. Bob McDonnell (R). Cuccinelli was embarrassed when it emerged that he had received smaller gifts from the same businessman.

Meanwhile, the GOP pounded McAuliffe over such controversies as two federal investigations into an electric car company he co-founded.

The ethics issue is not going away. The new governor’s every step in office will attract extra scrutiny for possible conflicts of interest.

The middle triumphs again. One truism about Virginia politics was reaffirmed: The candidate who prevails is the one who persuades voters that he or she will hew to the middle.

McAuliffe’s top campaign officials said the Democrat’s greatest success was in presenting himself as a bipartisan problem solver. The Democrat wooed and won backing from a string of Republican politicians and featured their support in ads.

Now McAuliffe has four years to try to square the circle between his promise of bipartisanship and his liberal campaign positions. The outcome will determine whether Virginia’s glide to the left continues.

For previous Robert McCartney columns, go to washingtonpost.com/mccartney.