Correction: An earlier version of this article, in noting that inner suburbs of Washington include a far higher proportion of Democrats than the state as a whole, incorrectly referred to “registered Democrats.” Voter registration in Virginia does not involve a party declaration. This version has been corrected.

President Obama barnstormed five cities across Virginia this weekend, stepping up his attacks on Republican Mitt Romney as the two candidates demonstrated the hard fight ahead in a state crucial to the battle for the White House.

Romney sent an army of surrogates into Virginia to counter the president’s fast-paced, two-day swing. The Republican’s campaign bus circled Obama’s events, former New York City mayor Rudolph Giuliani made an appearance, and scores of local Republicans lined the road with banners and posters to protest Obama’s appearance at a Northern Virginia high school Saturday.

The focus on Virginia’s cities, suburbs, mountains and military bases captures dramatically how varied and unpredictable the state is despite the president’s historic victory here in 2008. Both candidates see great opportunity in the political geography of the Old Dominion, and neither is certain of winning it.

“Let me just say this,” Obama told a crowd of more than 3,000 packed into a four-block stretch of downtown Roanoke late Friday. “If I win Virginia, I’m going to get four more years. That I can say with some confidence.”

Obama continued his blitz on Romney’s record at Bain Capital even after the Republican demanded an apology for the president's sharp attacks. Instead of offering one, Obama debuted a tough new ad in nine states, including Virginia, accusing Bain of moving jobs overseas and even mocking Romney’s rendition of “America the Beautiful.” At one appearance, the president declared: “I believe in insourcing.”

Virginia’s evolution into electoral battleground is a story best told with a map. The commonwealth was once deeply conservative, and Republicans still dominate the southern and western rural swaths. But growing minority populations in the eastern cities and inner suburbs, younger and independent-minded military families in Hampton Roads, and moderate newcomers to the booming exurbs of Washington and Richmond have transformed Virginia into one of the most important presidential battlegrounds of the year.

Gov. Robert F. McDonnell (R) noted that in 2009 he won virtually all the Virginia battlegrounds that pushed Obama to victory the year before.

“It’s the kitchen-table voters,” McDonnell said. “Thirty percent of voters in Virginia, maybe even more in the suburbs and exurbs, are people who really don’t vote party. They vote the person, and they vote the issue. And from what I’m hearing from people, and from what the polls indicate are important to people, the president’s got a horrible record and Mitt Romney’s got better ideas.”

All over the map

Obama’s itinerary Friday and Saturday reflected Virginia’s changing political map. A few miles from Oceana Naval Air Station in Virginia Beach, he met with Navy families over lunch. He drew large minority crowds in Hampton, an urban enclave in Tidewater. He stopped in Roanoke — he is the first sitting president in decades to do so — trying to expand the valuable concentrations of Democrats in western Virginia’s string of small cities. And he hit the vote-rich outskirts of Richmond and Washington, ground zero for Virginia’s political evolution.

Some of those groups remain up for grabs, and some are out of reach. The independent voters Obama is courting among suburbanites, service members, business leaders and federal workers are on Romney’s radar, too. McDonnell noted that two of Obama’s five stops this weekend — in Virginia Beach and Glen Allen — were in Republican neighborhoods where McDonnell has lived. (Glen Allen, where Obama spoke in a drenching thunderstorm, is also in House Majority Leader Eric Cantor’s district). And deeply conservative rural Virginia serves as a constant reminder for Obama that, despite the opportunities, his path to victory here is narrow.

“We have a very legitimate opportunity to win races that we weren’t winning before,” said U.S. Senate candidate and former governor Timothy M. Kaine. “But it’s nothing to be cocky or complacent about.”

It was fitting that Obama traveled the state Friday with the two Democrats, Kaine and U.S. Sen. Mark R. Warner, who redrew Virginia’s political map over the past decade.

Warner, a business-friendly cellphone millionaire, used his moderate, pro-business record to persuade a vast sea of independents across Virginia, even in the rural swaths, to vote Democratic after years when that was out of the question for them.

And Kaine, a former Richmond mayor and civil rights lawyer who had been expected to struggle with those same independents in his 2005 gubernatorial bid, targeted — and won — a whole other category of receptive voters: moderate suburban newcomers.

One coveted group of Virginia voters targeted heavily by both sides this weekend are military families. On Friday, Obama made an unscheduled stop at Rick’s Cafe in Virginia Beach to meet with military spouses and promote his increases in funds for veterans services, programs to support military families and efforts to encourage employers to hire returning service members.

“Prior to this administration, you never heard about military families,” Jennifer Farlin, a mother of two young boys and wife of a Navy commander serving overseas, told the president. “It makes me feel very supported.”

Obama also chose Ricki Thompson to introduce him at his main event in Virginia Beach. She is a Navy veteran, a Navy spouse and a mom — a trifecta of appealing attributes for the voters the president is courting.

A day ahead of Obama’s Virginia swing, Romney reached out to military families, too, launching an aggressive effort to blame the president for deep cuts due to hit the Pentagon next year.

“What was designed to be a political hammer over both parties is now getting close to reality and is causing a disaster of uncertainty for the Defense Department and job creators in the defense industry all over the country,” McDonnell said.

Both the White House and Obama’s Chicago-based campaign pushed back against the accusation by explaining that the cuts were made intentionally onerous by both parties to encourage them to come to broader agreement on how to reduce the national debt.

Virginia demographics

Electoral results and recent polling by The Washington Post show how demographically varied Virginia is.

The inner suburbs of Washington, for instance, feature far more Democrats proportionally than the state overall. Rural Virginia is so much more conservative than the more populous east that, in 2008, Obama ran 12 points behind his overall performance in Virginia. And in Tidewater, where Obama made two stops Friday, black voters constitute 38 percent of voters, twice the percentage of the entire state.

The president’s enormous popularity among black voters was on full display throughout the weekend swing. Motorcading through minority-heavy neighborhoods in Norfolk, Virginia Beach and Hampton, Obama traveled boulevards lined with supporters who jumped, cheered and waved signs as he passed. One woman came out of a beauty parlor, her hair still in curlers, during his brief stop at Rick’s Cafe. A teenage girl fainted during his speech at Green Run High School. And at Phoebus High School in Hampton, he couldn’t finish a sentence without being interrupted by exuberant cheers.

“We got your back, Obama!” one woman screamed.

Laura Vozzella and Peyton M. Craighill contributed to this report.