TYSONS CORNER, Va. -- Democrat Terry McAuliffe narrowly bested Republican Attorney General Ken Cuccinelli to become the next governor of Virginia on Tuesday, underperforming the polls that have shown him for weeks to be a strong frontrunner.

With more than 99 percent of precincts reporting, McAuliffe led Cuccinelli by less than 2 percent — 48 percent to 46 percent — or roughly 40,000 votes.

The outcome, although ultimately a nail-biter, was not only an important victory for the Democratic Party, which faced a challenging political landscape and demographics in a swing state during a non-presidential election cycle, but also for McAuliffe personally, marking the first elected office he has held.

“This race was never a choice between Democrats or Republicans,” McAuliffe said in his victory speech to an excited crowd of supporters in a hotel ballroom, “it was a choice about whether Virginia would continue the mainstream bipartisan tradition that has served us so well over the past decade.”

The path to victory for McAuliffe, who led in the polls and in fundraising throughout the race, was paved with historic spending for a Virginia gubernatorial race, broad negative messaging on both sides, and campaign-trail cameos by national political figures of each party.

President Barack Obama, former President Bill Clinton and former Secretary of State Hillary Clinton all campaigned for McAuliffe, among others, while Sens. Rand Paul, Ted Cruz and Marco Rubio were among the public supporters of Cuccinelli's bid.

In the final days of the campaign, Cuccinelli and Republicans attempted to draw in voters with a national message to capitalize on President Barack Obama’s low approval rating and faltering public support for his signature healthcare law. Cuccinelli declared Monday that the election would be a “referendum” on Obamacare — and insisted as much even as he conceded the race in Richmond on Tuesday.

"This race came down to the wire because of Obamacare," Cuccinelli said.

In their victory, Democrats will contend that voters rejected the Tea Party and its policies, and that the electorate is shifting its support away from the Republican Party one year out from the midterm elections.

It is possible that on-the-ground efforts by Democrats could serve as a model for other swing-state Democrats in the next election cycle.

McAuliffe’s campaign was capped off by a robust get-out-the-vote effort that, early exit polls indicated, drove voter turnout closer to that of 2012, a presidential election year, than 2009, the last gubernatorial election in Virginia. But late results appeared closer to a normal non-presidential election year than those early results suggested.

Democrats could also turn to McAuliffe’s fundraising for important hints at how to draw in support from moderate Republican donors, as he managed to. Throughout the campaign, McAuliffe’s fundraising dwarfed that of Cuccinelli. But as of the last week of October, McAuliffe had brought in roughly $40 million, compared to about half that for Cuccinelli.

That money enabled McAuliffe to handily outpace Cuccinelli in television advertising, but particularly during the last few weeks of the election when it mattered most. During the week of Oct. 28, McAuliffe’s campaign ran roughly 2,500 TV ads, compared to 1,500 aired by Cuccinelli’s campaign. McAuliffe’s ad-buy regimen matched up much more closely with Gov. Bob McDonnell’s successful bid for governor in 2009.

Polls in the final days of the election showed McAuliffe leading Cuccinelli by roughly six or seven points — a distinct but not commanding lead.

Driving voters to an abnormal extent were issues such as abortion and access to birth control, which McAuliffe’s campaign spent vast resources to tie to Cuccinelli, who supported strict limits on both.

Cuccinelli was forced to contend not only with Democrats’ negative advertising and massive spending, but also with his own conservative policies that alienated some voters — and, at certain junctures, members of his own party.

He won his party’s nomination due in no small part to a decision to elect by a convention instead of a primary, and his staunch conservative stances thereafter drove many moderate, pro-business Republicans to McAuliffe.

But McAuliffe faced his own obstacles, including his ties to GreenTech Automotive, a company that federal officials investigated for potentially having received special treatment from the government, and his other investments that helped him to accrue enormous wealth.

Some voters were left dissatisfied with both candidates and drove Robert Sarvis, an Independent candidate, to eat up a chunk of votes, many of which polls show likely would otherwise have gone for Cuccinelli.

This story was first published on Nov. 5 at 10:47 p.m.