DES MOINES, Iowa Jan. 4, 2012 -- Mitt Romney won the first presidential preference contest of 2012 by a mere eight votes Tuesday, narrowly edging out a surging Rick Santorum in the Iowa Caucuses.

The two men -- neither of whom was expected as recently as a month ago to win -- ran neck and neck and finished in a virtual tie. The second place finish capped a remarkable rise in popularity for Santorum, who had focused his entire campaign and shoestring budget on Iowa.

Romney finished second in Iowa in 2008, but had focused his 2012 campaign on other early primary and caucus states. In this cycle he received exactly six votes less than he did in 2008.

In third place was Rep. Ron Paul, the Libertarian leaning Texan on his third and most inspired run for the presidency.

Read analysis of the Iowa results and whether Santorum can carry his momentum to other states.

There were some reporting irregularities from local party committees that dragged the election outcome into the wee hours of Wednesday morning.

Both candidates gave speeches earlier in the night that sounded victorious. ABC News projected that 123,000 people voted in the Iowa contest, the largest turnout for a Republican caucus. Romney got 30,015 votes and Santorum received 30,007.

Santorum was boosted by evangelical Christians, an influential group in the state, and voters who made their decision in just the last few days. A Des Moines Register poll Saturday found that as many as four in 10 Republican voters in Iowa were still undecided.

While Santorum's showing is an upset of sorts, Romney's narrow victory places the former Massachusetts governor in a good position to win New Hampshire's primary next week before the candidates face off in a more competitive primary in South Carolina. He's also expected to get the endorsement of Sen. John McCain, the last Republican nominee for president.

Romney gets bragging rights to the victory, but no delegates are awarded as a result of the Iowa caucus.

Read more about the upcoming primary contests.

Paul, in third place, held on to his reliable bloc of enthusiastic supporters and ended up with 21 percent of the vote. The rest of the candidates fell into a lower tier, with Newt Gingrich winning 13 percent, Rick Perry getting 10 percent and Michele Bachmann seeing 5 percent.

In a late-night speech that stressed his blue-collar roots, Santorum noted the "rather close race" he's in with Romney, and as he argued why he's a better candidate, a supporter shouted out, "RomneyCare," referring to the ex-governor's health care record in Massachusetts that has haunted him.

"What did you say? Oh, RomneyCare, OK. I just didn't hear you," Santorum said. "What wins in America are bold ideas, sharp contrasts and a plan that includes everyone."

Romney, in his speech just moments later, congratulated Santorum and Paul but spoke almost entirely about President Obama. Citing a quote Obama made three years ago -- that if the economy isn't better, he might only last one term -- Romney told cheering supporters that "we are here to collect."

The results from Iowa appeared to claim at least one casualty: Perry announced late in the night that he would go home because of his poor showing, appearing to surprise members of his staff.

"I've decided to return to Texas to assess the results of tonight's caucus, determine whether there is a path forward for myself in this race," he told his supporters. Perry's campaign said he made the decision an hour before he took the stage.

And Bachmann's campaign manager told the AP that "it's hard to tell" whether the congresswoman will keep campaigning. Both Perry and Bachmann planned on skipping the New Hampshire primary to focus solely on South Carolina.

Gingrich, who finished fourth, praised Santorum for running a positive campaign but was openly bitter toward Romney, who has benefited as a Super PAC spent millions of dollars to wipe out Gingrich's onetime lead.

"He waged a great, positive campaign," Gingrich said of Santorum in his speech to supporters. "I wish I could say that for all the candidates."

Romney is expected to win the New Hampshire primary, setting a dramatic stage for the South Carolina contest on Jan. 21. William Galston, a veteran of Democratic presidential campaigns, predicted late Tuesday that if Gingrich stays in the race through the South Carolina primary, Romney could benefit if conservative voters split their votes among more than one conservative.

"The remaining question is whether Santorum will be able to rally the anti-Romney forces in South Carolina," Galston said. "If not, Romney's the nominee-early."

Democrats used the Iowa caucus as a chance to sharpen the focus on Romney.

"After five years of campaigning and adopting policies far to the right of Rick Perry, Rick Santorum, and Newt Gingrich on issues ranging from economic philosophy, to immigration, to social issues, Mitt Romney still failed to convince voters that he could be trusted to help middle class families and those still trying to reach the middle class," Democratic National Committee Chairwoman Debbie Wasserman Schultz said in a statement.

In the ballroom of a Des Moines hotel, hundreds of Romney supporters cheered as they watched the returns. Campaign aides said the entire family was watching the results "intently" as he and Santorum were separated by just a handful of votes.

More than a hundred jubilant supporters jammed into Paul's party at the Marriott in Ankeny, about 20 minutes north of Des Moines, to hear he claim there "were essentially three winners" tonight.

"We're ready and raring to move on to the next stop, which is New Hampshire," he said.

Gingrich said he would continue to fight in the New Hampshire primary. "We are not going to go out and run nasty ads ... but I do reserve the right to tell the truth," he said, suggesting the truth could seem to be negative.

Gingrich also took a swipe at Paul, saying some of Paul's views are "stunningly dangerous for the United States of America."

Romney did well among voters looking for the candidate who they think is best able to beat Obama, which one-third of Iowa voters polled said they considered a leading candidate attribute. Romney also did better among older voters who make up a key part of the Iowa electorate.

What could be a troublesome signal for the former Massachusetts governor moving forward is that he did less well among very conservatives this year than he did in 2008, suggesting he's still got a long way to go to close the deal with the conservative base.

Read more about the early entrance poll results here.

Paul did well among independents who came out in much larger numbers than usual. Entrance polls found that 24 percent of tonight participants -- twice as many as 2008 -- identified themselves as independents. The Texas congressman also did particularly well with young participants and the four in 10 voters who were attending their first caucus. But it was not enough to propel the libertarian-leaning candidate to first place.

Romney watched the returns come on TV at the hotel Fort Des Moines with one of his sons and advisers. His wife, Ann, and their three other sons were making their way back here from the precincts where they all spoke on behalf of Romney.

Romney made an aggressive last-minute push to lure undecided voters, logging more miles in Iowa in the last seven days than in the entire primary season combined.

On Tuesday, he focused his campaign on attacking Obama.

"This has been a failed presidency," Romney said at an event in Des Moines. "I will go to work to get Americans back to work."

View the real-time results here.

Santorum's unexpected surge in the polls just days before the Iowa caucus helped jolt new life into the former senator's presidential campaign. Just a few weeks ago, Santorum's events were filled with empty seats. This week, his events went over capacity. The former congressman watched the returns with his family at a hotel in Johnston, as his campaign expressed cautious optimism.

Santorum's fundraising has tripled in the last week, his campaign manager Mike Biundo told reporters, and they are now running ads in New Hampshire and South Carolina. Biundo said they will be hiring more staff.

"We are going to hire more people, but we are not going to spend millions and millions of dollars like these other campaigns. We feel that we can do it a little bit different. We can do a lot of grassroots because we have the support out there, but we will be expanding our staff," Biundo said.

"This is the first step, this is the first step," Santorum told ABC News after his last Iowa campaign stop in Urbandale. "A win here is a start, but it's a start. It's not the culmination, it's a start. It's not the culmination, it's the beginning."

Other candidates haven't fared so well. Bachmann set the record for the largest fall in popularity in Iowa history, from winning the straw poll to losing the caucuses. Bachmann won the Iowa straw poll in August with 28.6 percent of the vote. Tonight she won only 5 percent.

Huntsman, who was notably absent in Iowa, focused all his efforts in New Hampshire, as did Gingrich, who slid sharply in the polls after the Romney campaign pounced on him with negative ads.

ABC News' Jake Tapper, Gary Langer, Elicia Dover, Amy Bingham, Elizabeth Hartfield, Jason Volack and Matt Negrin contributed to this report.