With most precincts reporting, McAuliffe had 47.4 percent of the vote to 45.8 percent for his Republican rival, the state board of elections said.
The Democratic candidate for lieutenant governor, state Sen. Ralph Northam, won by a much bigger margin. Northam got 55 percent of the vote to 45 percent for E.W. Jackson, a black minister and Christian conservative.
Democrats had hoped to sweep all statewide offices for the first time in years. But Mark Herring, the Democratic candidate for attorney general, was trailing with 49.50 percent of the vote to 50.38 percent for Republican Mark Obenshain.
In his concession speech, Cuccinelli claimed a sort of moral victory, framing the vote as a referendum on the Affordable Care Act, The Washington Post reported.
"Despite being outspent by an unprecedented $15 million, this race came down to the wire because of Obamacare. That message will go out across America tonight," he told supporters.
The governor's race tightened considerably in its last days. Late polls showed McAuliffe ahead by several percentage points, down from a double-digit lead earlier.
2014: The Year in Music [PHOTOS]