DES MOINES — Mitt Romney’s quest to swiftly lock down the Republican presidential nomination with a commanding finish in the Iowa caucuses was undercut on Tuesday night by the surging candidacy of Rick Santorum, who fought him to a draw on a shoestring budget by winning over conservatives who remain skeptical of Mr. Romney.

In the first Republican contest of the season, the two candidates were separated much of the night by only a sliver of votes, with Mr. Romney being declared the winner by eight ballots early Wednesday morning. But the outcome offered Mr. Santorum a chance to emerge as the alternative to Mr. Romney as the race moves to New Hampshire and South Carolina without Gov. Rick Perry, who announced that he was returning to Texas to assess his candidacy.

“Being here in Iowa has made me a better candidate,” Mr. Santorum said, arriving at a caucus in Clive, where he urged Republicans to vote their conscience. “Don’t sell America short. Don’t put someone out there from Iowa who isn’t capable of doing what America needs done.”

The Iowa caucuses did not deliver a clean answer to what type of candidate Republicans intend to rally behind to try to defeat President Obama and win back the White House. With 99 percent of the vote counted, Mr. Santorum and Mr. Romney, whose views represent the polar sides of the party, each had 24.6 percent.