The call from President Obama’s campaign team went out quickly once news spread that voting lines in crucial, minority-heavy precincts in Prince William County were approaching four hours.

Advisers asked local politicians to head over to cheer up waiting voters. As evening fell and the temperature dropped in the Washington outer suburb, they persuaded local election officials to let voters stand indoors. Finally, after polls had closed with thousands still waiting, they blasted an urgent text message to supporters across the region: “Volunteers are needed right now to make sure everyone who’s still in line gets to vote! Reply with VAPOLLS and an organizer will call you.”

Obama said all along that he would defeat Mitt Romney in part because of a second-to-none field organization. Nothing proved his point more aptly than how that organization performed Election Day.

After years amassing unsurpassed data about potential Obama voters, building armies of volunteers who connected repeatedly with those voters and assembling teams of analysts, lawyers and other decision-makers who studied the projections, the laws and the electorates in each battleground, they prepared for every contingency they could think of that might come their way Election Day.

It was “the best campaign team and volunteers in the history of politics,” Obama proclaimed in his victory speech in Chicago early Wednesday, an observation that prompted grudging acquiescence from some Republicans.

His historic candidacy in 2008 produced a field organization and volunteer army that was, on Tuesday, five years in the making. The generals of that army argue that the president’s win this time, although narrower, proves that their methods are crucial for any campaign.

“People could have said it was the ‘Obama magic’ in 2008, but I don’t think you can say that about 2012,” said Jeremy Bird, Obama’s field director. “He was entering a really tough race. Most people in the media a year ago were saying this was going to be a really tough race for him.”

Republican National Committee spokesman Sean Spicer acknowledged that the Democratic ground operation outpaced the Republican side. But the Republican field organization was strong, he said, meaning there was more to Obama’s victory, including better assumptions and data about enthusiasm and who would vote.

“They won. We’re going to do a lot of analysis, but our ground game was better than it’s ever been before,” Spicer said. “We took our ground game to a new level; we just came up short. So it’s like any other team. You can play better than you’ve ever played before, but if the other team outdoes you, they’ll win the game.”

Obama, a former community organizer, decided early on that he would build on the field organization of four years ago — and do it in nine crucial battlegrounds that he won in 2008. Virginia is a case in point: a state he won easily four years ago but that his advisers knew would be harder this time around.

In a state known for its rural conservatism and independent-minded suburbs, the president’s supporters would need to find every person open to voting for him, make sure they were registered, persuade them to choose him, and, finally, turn them out to vote.

An early task was building the field staff and army of volunteers who would do all this hard work. Romney’s political director, Rich Beeson, regularly mocked the number of field offices Obama opened across the battlegrounds, saying storefronts in obscure towns wouldn’t translate to votes.

But in Obama’s case, they did. Among more than 60 offices across Virginia, the connection is clear between their locations and the voter groups that pushed Obama to victory. Two were opened in southeastern Prince William County, an African American enclave that turned out heavily for Obama in 2008 — and did so again Tuesday. Offices were placed in white exurbs, too — in Chesterfield and Leesburg, for example, from which to target independent-minded voters, particularly women, who were at risk of turning away from Obama after voting for him the first time. Romney did worse than expected in those places.

Those offices were staffed with paid field organizers. But they also attracted thousands of volunteers who were recruited via e-mail and text messaging from voter files of known Obama supporters, donors and past volunteers.

Richard Russo was one of those volunteers. The nonprofit program manager from Alexandria gave five to six hours a week to the campaign for much of the year, making calls, knocking on doors and delivering the message that organizers told him to deliver.

Through the evolution of those instructions as the year progressed, Russo could see the methodology that went into the field operation. Early in the year, he called voters simply to verify the accuracy of the list: were they registered, were they likely to vote, which candidate did they lean toward? Over the summer, the script changed to persuasion; Russo’s lists featured undecided voters open to supporting Obama. And he talked to them about the president’s plans to protect the middle class, his support for issues of importance to women, Romney’s conservatism.

“It was so precise, so surgical, so accurate,” Russo said.

Voter registration was a priority through the year. The campaign registered more than 100,000 new voters in Virginia since 2008, more than the size of Obama’s margin of victory in the commonwealth.

By the final weekend of the cycle, the campaign was targeting a precise list of 500,000 people who supported Obama but weren’t certain to vote. Either by phone or with a knock on the door, and in many cases both, teams of more than 20,000 volunteers reached nearly every one of those voters, the campaign said. Over the course of the campaign, those voters were contacted an average of seven times — often by the same volunteer, a testament to the value placed by the campaign on personal connections.

The final piece of the whole operation was the plan for Election Day, and the events in Prince William were a case in point. Campaign officials got reports that lines were growing and realized that voters might go home without casting their ballots.

They called Rep. Gerald E. Connolly (D-Va.), one of their leading surrogates in Virginia, as well as Del. Luke Torian, a local minister with deep ties in southern Prince William, and asked them to rush to the precincts where the lines were the worst.

“We provided water, we provided encouragement, and we finally prevailed on the local election judge to allow the voters to come in on the inside to stay warm,” Connolly said.

In the end, it worked. Connolly said he saw no one give up at the precincts he visited.

“I have not waited four hours for anything — traffic, nothing,” said Annie Sasjous, 49, who waited four hours and 10 minutes to vote for Obama. “This was perseverance. People in the line were saying, ‘Press on, press on.’ ”

T. Rees Shapiro contributed to this report.