Rick Perry
Rick Perry campaigning in Iowa in 2011. The early caucus state may see him again in 2015. Reuters

(Reuters) - Even Rick Perry's top advisers thought it was over.

After the Texas governor finished fifth in the Iowa caucuses on Tuesday night, his staff and volunteers gathered around the bar in a Des Moines hotel to say goodbyes, drink beer and mourn what appeared to be the end of his quest for the Republican nomination for president.

Perry had, after all, just said that he would return to Texas and reassess his campaign in a speech that had all the markings of a withdrawal from the race.

Only it wasn't. Less than 12 hours later, Perry - still in Iowa - surprisingly declared that he would continue in the race, and make South Carolina his make-or-break state.

What changed his mind?

Senior Perry aides, friends and staff members told Reuters that after a restless night, Perry and his staff ultimately decided there were four reasons the campaign should continue.

Most significantly, his team essentially calculated that Rick Santorum, who emerged in Iowa as the leading conservative alternative to former Massachusetts Gov. Mitt Romney, isn't a strong enough candidate to hold that position in future contests.

Perry's campaign also received calls from supporters in Texas, who urged the governor not to give up. And Perry aides determined that their campaign - more so than those of Santorum, a former U.S. senator from Pennsylvania, or former House Speaker Newt Gingrich - had the organization and fund-raising abilities to compete with Romney in the South Carolina primary on Jan. 21.

Finally, Perry decided that he did not want to leave the race without competing in South Carolina, a state whose conservative voting base is more in line with his politics than middle-of-the road Iowa or New Hampshire, which will hold its primary on Tuesday.

Finishing behind Romney, Santorum, Texas Rep. Ron Paul and Gingrich in Iowa made for a tough night, said Perry senior aide Ray Sullivan, who while at the hotel bar late Tuesday had spoken lovingly of being able to spend the next night in his own bed in Austin, Texas.

But in the light of day, there was ample reason and ability to continue, Sullivan said.

A Republican strategist with ties to the campaign said the Texas governor's staff determined that there's still going to be an anti-Romney candidate, and the field to become that person isn't strong.

The other Republicans competing for the nomination to challenge Democratic President Barack Obama in November's election all have about equal odds to be the anti-Romney, the strategist said. If that's true, you might as well stay in to South Carolina.

Sullivan agreed, saying We are much better positioned to be that person than Santorum, whose fundraising operation pales in comparison with Perry's.

Sullivan said Perry's campaign came to believe that Santorum did well in Iowa, narrowly losing to Romney, only because Santorum surged at the right time. And Santorum did so, Sullivan said, having been largely unexamined and unvetted.

The scrutiny surrounding Santorum has increased since his finish in Iowa.

In New Hampshire to campaign for Romney, 2008 Republican presidential nominee John McCain said that as a member of Congress, Santorum was a defender of wasteful pork barrel spending when it came to securing federal money for Pennsylvania.

During this campaign, Santorum had not really been examined or exposed before the Iowa caucuses, Sullivan said.

'MILLIONS OF DOLLARS' AVAILABLE

Perry, who briefly led opinion polls in the Republican race until poor performances in televised debates drove his numbers down, still has considerable ability to raise money for his campaign, Sullivan said.

Perry's campaign raised $17 million during the third quarter, and has been spending millions on advertising since then. Spending reports for the months leading into the Iowa caucuses have not been released, but Sullivan said Perry has enough of a donor base and millions of dollars to continue a strong campaign.

A senior adviser to Romney's campaign said on Tuesday: When you're the governor of Texas, you're never broke.

Told of that assessment, Sullivan chuckled and said: That's not a bad analysis.

A source close to Perry's campaign said he still could go to his donors in major Texas cities and raise $2 or $3 million, at least.

Texas is not tapped out, the source said.

Among those who talked with Perry and urged him to stay in the race was Thomas Graham, a friend and Texas-based political consultant.

Graham told Perry, who has made patriotism a recurring theme on the campaign trail, that the governor could do well in South Carolina in part because of the state's concentration of socially conservative voters and military personnel.

As he was leaving the building on Tuesday night, I told him, 'You've got men and women who have stood up for our country all over the world, and they're standing up for you. You need to continue to stand up for them,' Graham said. That's what I said to him.

Perry, an Air Force veteran, has been endorsed by several high-profile veterans, Graham said, and that will play well in South Carolina.

There are 450,000 veterans in South Carolina, Graham said. No candidate, including the president of the United States, has the record on veterans issues that Rick Perry has. And it's a mistake not to take that message to South Carolina and Florida - where there are 1.75 million veterans.

Katon Dawson, a Perry supporter and a former chairman of the South Carolina Republican Party, said Perry also was staying in the race to run in what Dawson called the first reliably Republican state to vote in the nominating process.

We haven't had our say down here, Dawson said. These South Carolinians are not going to let Iowa pick our president.

(Additional reporting by Karen Brooks in Austin, Texas; Editing by David Lindsey and Christopher Wilson)