Virginia’s governors race was close — closer than the pre-election polls suggested it would be. Dissatisfaction with President Obama’s health-care law appears to have fueled a last-minute surge for Republican Ken Cuccinelli II. Analysts are latching onto how he exceeded expectations, and what a political liability Obamacare might turn out to be in next year’s midterm elections.

But Republicans must take the right lesson from their loss. They should have won this election. Why didn’t Cuccinelli pull it out?

In part, it was the presence of a third-party candidate, libertarian Robert Sarvis, in the race. But Sarvis’s success and Cuccinelli’s failure to win Virginia’s moderate swing counties both point to the same underlying problem: Cuccinelli’s severe politics. The state’s voters wisely spared themselves four years of extremism.

McAuliffe and Cuccinelli debate
Democratic gubernatorial candidate, Terry McAuliffe, left, shakes the hand of Republican challenger Virginia Attorney General Ken Cuccinelli, right, after a debate at Virginia Tech in Blacksburg, Va., Thursday, Oct. 24, 2013. (AP Photo/Steve Helber)

Terry McAuliffe, a weak Democratic candidate with little experience and a record of murky business associations, got nearly half the vote in the purplest of purple states, even with Sarvis nabbing his 7 percent. McAuliffe consistently led the RealClearPolitics average of polls from the beginning of September — as far back as the site will go. That in an off-year election during a second-term Democratic presidency that is in the midst of an incompetent health-care rollout.

Something drove centrists — and, no doubt, a fair number of typically Republican voters — away from Cuccinelli.

Maybe it was . . . Cuccinelli.

Just Google him. The top autofill results for “cuccinelli” are:

cuccinelli poll

cuccinelli sodomy

cuccinelli divorce

cuccinelli abortion

cuccinelli birth control

This is the man who tried to make divorce harder in Virginia, the man who used the state attorney general’s office to hound a climate-change scientist, and the man who favored a “personhood” measure that would have opened the way to restrict popular forms of contraception. This is the politician who declared, “Homosexual acts are wrong. They’re intrinsically wrong. And I think in a natural law-based country it’s appropriate to have policies that reflect that.”

He’s also the leader who fought an unspectacular but desperately needed transportation plan, reconfirming that he is more interested in ideology than pragmatic accomplishment.

Here’s the lesson for Republicans: They have to stop nominating ideologically pure right-wingers who scare lots of voters — Cuccinellis, Richard Mourdocks, Sharron Angles, Christine O’Donnells and Todd Akins. They don’t win outside of deep-red territory, and they would hurt the party even more if they did.

Most voters don’t want the tea party, or whatever you want to call the vocal swath of the uncompromising hard right that too often picks GOP candidates these days. They don’t want tea party tactics — like the shutdown. And they don’t want tea party policy, either. After several election cycles in which Republicans have surrendered winnable races to Democrats, this should be obvious.

Follow Stephen Stromberg on Twitter: @strombergsteve

Stephen Stromberg is a Post editorial writer. He specializes in domestic policy, including energy, the environment, legal affairs and public health.