Democrat Terry McAuliffe narrowly beat Republican Ken Cuccinelli in an expensive and hard-fought race Tuesday night that ended with the Virginia governorship back in the hands of a Democrat, according to NBC News.

With nearly all precincts reporting, McAuliffe only led 47% to Cuccinelli’s 45%. Libertarian Robert Sarvis, who many expected to pull more votes from Cucinelli, took just under 7%.

But McAuliffe’s win was closer than expected against the deeply conservative Cuccinelli, the current attorney general. While many expected the Demorat’s win in the once GOP-stronghold of Virginia to provide further evidence of the difficulty conservative candidates have in swing states, the narrow margin could actually inflame the tensions within the GOP. Many in the GOP establishment didn’t get on board with the Tea Party-backed Cuccinelli’s campaign, and key national dollars stopped flowing into the race in the the closing days as Cuccinelli was especially outspent in the vote-rich Northern Virginia media market. He brought in Tea Party surrogates in the final hours, but perhaps the man who could have helped him most took a pass. According to various senior Republicans helping Cuccinelli, they tried getting Gov. Chris Christie to come campaign for Cuccinelli, but the New Jersey Republican, who rolled to a win in the blue Garden State, refused.

But Cuccinelli’s late push in the race to frame the vote as a referendum on the president’s health care plan could be an important sign of worry for Democrats. In his concession speech, Cuccinelli said the tightening of the race was a victory against the controversial law that’s been plagued by problems since its implementation.

“Despite being outspent by an unprecedented $15 million this race came down to the wire because of Obamacare,” said Cuccnelli.

“We were lied to by our own government in its effort to restrict our liberty,” the losing Republican said, pointing to the president’s claims that “if you like your health insurance plan, you can keep it” as many have seen their plans cancelled.

Exit polls showed Obama’s approval actually higher than when Republicans rolled to a win in the 2009 race. In 2013 exit polls, 53% said they disapproved of the job the president was doing, compared to 51% in 2009 that was seen as a warning shot ahead of the 2010 GOP wave. Fifty-three percen talso said they opposed the health care law, and 27% said health care was the one issue that mattered most to them when making their vote, second only to the economy at 45%. Of those who listed health care, Cuccinelli won those voters 49%-45% – and he also carried voters most concerned about the economy, 49%-43%.

But in his victory speech, McAuliffe promised to reach across party lines as he took the reins.

“The truth is, this election was never a choice between Democrats or Republicans. It was a choice of whether Virginia could continue in a mainstream, bipartisan” way, said McAuliffe. “At a time Washington is broken, just think about what Virginia can accomplish when we work together.”

However, Democrats didn’t get the blue sweep they had hoped for in the state either –yet. They won the lieutenant governor’s race in the Old Dominion, with Democrat Ralph Northam topping controversial minister E.W. Jackson, but the tighetst race of the night was in the battle for attorney general. With less than 1% separating Demorat Mark Herring and Republcian Mark Obenshain, a recount is likely and NBC News is not making a call in the race.

Still, women, minorities and voters who consider themselves moderates all broke for McAuliffe in a race that was dominated by Cuccinelli’s conservative social views, including his opposition to abortion and gay marriage. The former chairman of the Democratic National Party, tied Cuccinelli to a deeply unpopular Republican Party that only suffered more damage in the wake of the government shutdown that especially impacted crucial government employees in the vote-rich Northern Virginia suburbs and exurbs. The result? According to exit polls, McAuliffe won women by eight points, a smaller gap than polls had consistently shown. In 2012, Obama carried female voters by nine points, while in 2009, Republican Gov. Bob McDonnell won female voters by six points.

Still, McAuliffe, a longtime aide and close friend of former President Bill Clinton and former Secretary of State Hillary Clinton, was plagued by reports of questionable business deals was seem by some as a cunning Washington money man. But it was Cuccinelli’s negatives were greater and McAuliffe successfully ran as the more pragmatic, bipartisan choice. According to exit polls, 50% of voters said they thought Cuccinelli was too conservative on the issues, while 48% said they thought McAuliffe was about right on his issue positions, though 42% said he was too liberal.

McAuliffe’s win marks the first time that Virginia’s off-year race has remained in the same hands as the president’s party, breaking a nearly four-decades long streak that dates back to 1973. It also continues a recent streak for Democrats in the fast-changing state, where they have won three out of the four past statewide elections – sweeping Senate races in 2008 and 2012 as Obama won the state too.

In the race for governor, it was McAuliffe’s campaign that rose to the challenge. Just four years after he ran a much-maligned campaign for the same office, and finished a distant second in the Demoratic primary, McAuliffe turned himself into a student of the state and built a sophisticated campaign operation staffed by many Clinton veterans who could factor into a potential 2016 Hillary Clinton White House bid.

The off year contest in Virginia typically sees a significant drop off at the polls from a presidential election – but turnout dramatically rose from 2009 and even 2005. Democrats said they were confident that voter turnout would top 40% and they would surpass 2 million votes – a milestone in any governor’s race in Virginia. Building off turnout models and high-tech get-out-the-vote operations from President Obama’s campaigns, Democrats knocked on 2.5 million doors by the time the campaign was over.

Cuccinelli’s campaign was pounded by McAuliffe’s ability to attract star power in President Obama and former President Clinton and a massive financial advantage, too. He outraised his GOP rival by almost $15 million. McAuliffe and his Democratic allies swamped Cuccinelli on the airwaves too, putting in $24 million to the Republican’s $17 million, according to NBC News. In the final months of the race, Cuccinelli was outspent on air by as much as 3-to-1. McAuliffe hadn’t trailed in a public poll in the race since July, and while the financial gap between the two became more pronounced later in the campaign, McAuliffe’s team argued their lead had already been set in place.

Early in the election, Democrats had been unenthused by McAuliffe’s past lackluster campaign and feared that Cuccinelli’s more fervent Tea Party supporters would swamp them in during the run up to the vote. But Cuccinelli’s own party had already soured on him, beginning with the way he secured the nomination. Cuccinelli allies, who had taken hold in the party, forced a convention rather than a primary to choose the nominee. Lt. Gov. Bill Bolling had his eye on the governor’s mansion after deferring to McDonnell in 2009. But he knew he couldn’t win at a gathering dominated by conservative party activists. He withdrew and pointedly declined to endorse Cuccinelli. Many GOP lawmakers defected or stayed on the sidelines, and even conservative editorial boards wouldn’t back Cuccinelli.

But much of the damage to the GOP candidate came from the string of ethics and gift scandal that enveloped and sidelined possibly Cuccinelli best surrogate, incumbent GOP Gov. Bob McDonnell. The sitting governor, who still remained highly popular, is under federal and state investigation for gifts and loans he accepted from Star Scientific CEO Jonnie Williams. Cuccinelli also accepted a Thanksgiving dinner and a stay at Williams’ home and had to amend his disclosure forms to reflect the $18,000 in gifts. Cuccinelli was cleared of any wrongdoing, but only after months of pressure he donated that value to a charity, and the damage had been done.

He was hammered on controversial statements he’d made on abortion, gay marriage and climate change. He tried to soften his image, boasting of his work on mental health, domestic violence, and even to free a man wrongly convicted of rape from prison, but the damage had been done.

The Old Dominion is a rapidly changing state – but also mirrors a rapidly changing country. There’s been a steady decline in the state’s white population as its Hispanic population has quadrupled since 1990 and doubled since 2000, along with steady growth in other minority groups. With Republican voting strongholds of older, white voters, it’s a problem magnified in Virginia and Cuccinelli’s loss.

That’s good news for Democrats looking to keep the state in their column in 2016 – but perhaps most important for Clinton now that McAuliffe is at the helm of the Old Dominion. The presidential frontrunner made her first post-State Department foray back into politics last month, and the former president made a four-day cross-state swing with the man once referred to as the “First Friend.” McAuliffe will be a close Clinton ally in a critical state, both in a primary and general, and many of his top staffers, including his campaign manager Robby Mook, could factor heavily into the former First Lady’s campaign team.

But it also should be a cautionary lesson for Republicans who often complained that they weren’t competitive nationally because they didn’t nominate the most conservative candidate. In Cuccinelli, they absolutely did. The damage to him was done early and he never recovered,. He was hammered on controversial statements he’d made on abortion, gay marriage and climate change. He tried to soften his image, boasting of his work on mental health, domestic violence, and even to free a man wrongly convicted of rape from prison, but the damage had been done.

Another final nail in his coffin – the 16-day government shutdown across the river, giving Democrats another chance to paint Cuccinelli with the broad brush of a Republican Party in turmoil. Privately, Republicans watching the race doubted he could recover from such a blow, and he never really did. In exit polls, voters put nearly equal blame on Republicans in Congress over President Obama for the shutdown, 47%-46%.

In the race’s final days, Cuccinelli tried to appeal to his base as the last hope to save him, bringing in conservative Tea Party surrogates like Sen. Rand Paul (R-Ky.), former Rep. Ron Paul (R-Texas), Sen. Marco Rubio (R-Fla.) and Gov. Scott Walker (R-Wis.). Amid the flawed, glitchy roll out of the president’s healthcare plan, he also sought to make the race a referendum on the president’s health care plan. By then, though, nothing could save him.

NBC’s Chuck Todd contributed to this report.