11.06.13 6:07 AM ET

Barring the return of Reconstruction, the concept of Terry McAuliffe as governor of Virginia once seemed laughable. This was a man who once downed shots on cable news and whose biggest political innovation was allowing major donors to stay over in the Lincoln Bedroom during the Clinton administration.

But the brash Democratic fundraiser and New York native was elected Tuesday by a margin of 48 to 46 over Ken Cuccinelli, the state’s socially conservative attorney general. Libertarian candidate Robert Sarvis drew just under 7 percent of the vote. The result was far closer than expected, as most public polls forecast a comfortable lead for McAuliffe.

In a brutally negative campaign, McAuliffe pulled out his narrow victory with a massive financial advantage and by painting Cuccinelli as an extreme social conservative. The Democrat also took advantage of Cuccinelli’s refusal to condemn the Republican tactics that led to the government shutdown. The issue was particularly potent in Northern Virginia, where many residents work for the government or for government contractors.

By contrast, Cuccinelli sought to focus on McAuliffe’s business deals and to turn the race into a referendum on Obamacare, which Cuccinelli has steadily opposed. While the strategy rallied ardent Republicans to his banner, it also may have energized some Democrats. Carrie Thierry of Henrico told The Daily Beast that Obamacare was one of her strongest motivations for supporting McAuliffe. Although she has always had health insurance, she said, she knows many people who are not so fortunate and said it is important they be covered.

McAuliffe’s key advantage lay in social issues such as abortion and birth control. He capitalized on Cuccinelli’s record of taking deeply conservative positions on those issues, most notably his defense of Virginia’s ban on sodomy laws. McAuliffe’s ads emphasized Cuccinelli’s absolute opposition to abortion, even in cases of rape and incest, and described him as anti-birth control.

The strategy helped McAuliffe rack up big numbers among women voters, winning them by a 51-42 margin even while narrowly losing among men. Linda Smith, an independent voter from Spotsylvania, told The Daily Beast that she voted for McAuliffe because she was turned off by Cuccinelli’s position on social issues. Jennifer Frederick, a Spotsylvania Democrat, put it more bluntly: “Cuccinelli scares the crap out of me,” she said.

The presence of a strong libertarian candidate also played a significant role in the race. Cuccinelli had Ron Paul headline his election-eve rally, and the Republican nominee spent far more time ignoring suburban swing voters in favor of wooing disgruntled libertarians than would have been ideal. While Sarvis only ended up polling about 6.5 percent, he had polled at more than 10 percent at times.

But Steve Waters, a prominent Republican strategist in Virginia, said Cuccinelli was simply stabbed in the back by his own party. Waters said the narrow loss was the result of fellow Republicans who jumped ship to back McAuliffe or, in the case of Bill Bolling, the state’s GOP lieutenant governor, simply sat on their hands. Bolling’s actions were emblematic of moderate establishment Republicans trying to undermine conservatives in the party, Waters said, comparing the lieutenant governor to the Washington Republicans who didn’t stand by Ted Cruz and Mike Lee in the government shutdown. A conservative lobbyist at the Cuccinelli party shared Waters’s contempt, noting that Bolling didn’t even contest the gubernatorial primary all the way to the convention. “Instead, he took his ball and went home,” the lobbyist said.

The defection of many Republicans, particularly those in the donor class, helped McAuliffe put together a whopping financial advantage. He outspent Cuccinelli by $15 million before taking outside groups such as the League of Conservation Voters and New York City Mayor Michael Bloomberg’s Independence PAC into account. McAuliffe also put together a far more effective ground operation than Cuccinelli, led by veteran Democratic organizer Robby Mook. During the governor-elect’s victory speech, he bragged that his campaign had knocked on 2.5 million doors since January, and he went out of his way to praise his field staff.

Down ballot, the conservative pastor E.W. Jackson lost by 10 points to Democratic state Sen. Ralph Northam for Lieutenant Governor. Jackson’s campaign had long been written off by Virginia Republicans as an undisciplined mess, and Cuccinelli rarely appeared with his running mate. The breach between Jackson and the rest of the party was made even clearer when he held a separate Election Night event rather than share the stage with Cuccinelli and the rest of the state Republican Party. One silver lining for the GOP in Jackson’s shambolic campaign was the optimism that the Republicans could pick off Northam’s state Senate seat in a special election. But that paled in comparison to the costs of a statewide campaign with an outlandish, gaffe-prone candidate. By contrast, the tightly matched race for attorney general between Republican Mark Obenshain and Democrat Mark Herring was too close to call on Election Night and was poised for a recount.

The contrast between the two gubernatorial candidates was never more clear than in their Election Night speeches. Both cited Thomas Jefferson and the importance of principle. Cuccinelli expressed his awe at the possibility that he might have succeeded the third president as governor of Virginia. He then went on to emphasize the importance of “first principles” of constitutional government and said his philosophy when he first ran for attorney general was “if there are enough people in Virginia who share our commitment to those first principles, we can’t lose and if there aren’t...we can’t win.”

McAuliffe, meanwhile, cited Thomas Jefferson’s first inaugural speech in 1800, saying his own differences with Cuccinelli and the GOP were “differences of opinion, not differences of principle.” Even when McAuliffe was noting that Virginians supported his “mainstream approach,” he emphasized that he was following predecessors of both parties, including Republican Gov. Bob McDonnell.

There’s no way to tell how McAuliffe will govern. After all, he’s never held elected office; he’s spent his career in politics as a fundraiser and party apparatchik. But one thing is certain: As a police officer watching McAuliffe’s victory speech said, Virginia is “gonna have to change the name on the highway signs now.”