President Obama secured a narrow victory in Virginia on Tuesday, capturing its 13 electoral votes and holding on to a state that Democrats see as symbolic of their ability to remake the nation's political map.

With more than 97 percent of the vote counted, the Virginia Board of Elections said that Obama had won at least 1.68 million votes -- nearly 50 percent of the vote. Republican Mitt Romney trailed by fewer than 50,000 votes.

Although Romney surged to an early lead, longtime Democratic strongholds ultimately delivered a slim victory for Obama.

Northern Virginia cast its lot with Obama, though in smaller numbers than it did in 2008. In Loudoun County, Obama won about 51 percent of the vote, though he won 54 percent there four years ago.

Arlington County swung back toward Romney, though the president still earned a victory in one of the Old Dominion's most populous counties.

While Obama won 73 percent of Arlington's vote in 2008, his 2012 haul dipped by about 6 percentage points.

Obama also claimed another victory in Fairfax County, the state's largest county, though his margin there also slipped.

Romney was depending on a strong turnout in the state's Hampton Roads region, home to the world's largest naval base and a huge number of Virginia's 822,000 veterans, to recapture the state for the GOP. And although Romney held a decisive edge over Obama in pre-election polls with military households, Obama still carried the region, relying on a heavy minority population to propel him to victory.

While Romney significantly improved on Republican John McCain's margins in Virginia Beach, he failed to make sufficient inroads in other parts of the region to give him the edge statewide.

Newport News gave Obama 64 percent of its vote, the same amount it did in 2008.

The city of Chesapeake was a bright spot for Romney, a place he flipped from blue to red. Obama won 50.2 percent of the vote there in 2008, but unofficial returns showed Romney winning the city by hundreds of votes.

Obama's win was his second consecutive victory in Virginia and marked the first time since 1948 that the state has voted for the Democratic presidential nominee in two straight elections.

But Obama's win was far slimmer than his 2008 victory. In that cycle, he won nearly 2 million votes and defeated McCain by a margin of more than 6 percentage points.

The GOP, however, regrouped in 2009 and swept every statewide race, a winning effort that the party said prepared it to mobilize this fall.

Democrats didn't take the state for granted, though, and both campaigns saturated Virginia with more than $86 million in television advertisements. Outside groups also flooded the state with millions in mailers and radio and TV spots.

In the campaign's closing days, both candidates and their running mates sprinted through Virginia, including an Election Day stop from Rep. Paul Ryan, Romney's running mate.

Romney visited on Sunday and Monday, holding three major rallies, and Obama drew a crowd of 24,000 to Bristow on Saturday.