Texas Gov. Rick Perry abandoned his presidential bid and endorsed Newt Gingrich on Thursday, just two days before the pivotal South Carolina primary, while Republican front-runner Mitt Romney struggled to fend off a growing challenge from the former House speaker.

"I know when it's time to make a strategic retreat," Perry told a news conference. He called Gingrich "a conservative visionary who can transform our country" and added, "Newt is not perfect, but who among us is?"

Perry had faced calls to drop out of the race to compel conservative voters, whose support has been divided among several conservative candidates, to rally behind Gingrich in hopes of stopping Romney. Recent polls show Gingrich gaining steam heading into Saturday's contest, but he still trails Romney by about 10 percentage points.

Perry had scarcely finished speaking when Gingrich issued a statement welcoming the endorsement. "I ask the supporters of Governor Perry to look at my record of balancing the budget, cutting spending, reforming welfare and enacting pro-growth policies to create millions of new jobs and humbly ask for their vote," Gingrich said.

Romney reacted by praising Perry for running "a campaign based upon love of country and conservative principles."

Perry's decision to endorse Gingrich does not necessarily mean conservatives will rally behind him. Rick Santorum, a former senator from Pennsylvania, is still in the race and over the weekend was endorsed by a group of evangelical leaders.

'I stepped in it'

Perry entered the race last August to great fanfare and high poll numbers. But his standing quickly fell after a series of mistakes called into question whether the Texas politician, who had never lost a race during his three-decade career in elected office, was ready for the national stage.

Perry's biggest error came in a nationally televised debate in early November, when he could not remember the name of the third cabinet department he pledged to eliminate.

"Oops," he said. Making fun of himself afterward, he told reporters: "I stepped in it."

The showing gave the impression that Perry couldn't articulate his own policies.

A Perry speech to a New Hampshire audience in October led to a damaging video, during which he appeared unusually animated — "loopy" to some observers — a stark contrast to the image of the serious, starchy governor he had projected.

Perry, 61, was relatively unknown outside of Texas until he succeeded George W. Bush as governor after Bush was elected president in 2000. A former Democrat, Perry went on to win election to the office three times to become the state's longest-serving chief executive

Santorum takes lead in Iowa

Santorum, meanwhile, edged Romney by 34 votes in a surprise flip to the final results of the Iowa caucuses, Republican officials said Thursday, but no winner was declared because some votes remain missing in the event's closest finish ever.

Romney had initially been considered the winner — by just 8 votes — of the first contest in the Republican presidential nomination contest.

Iowa Republican Chairman Matt Strawn announced the certified totals for the Jan. 3 caucuses at a news conference, but didn't name an official winner because some votes can't be counted. Results from 8 of the state's 1,774 precincts are missing.

"Just as I did on the early morning hours on Jan. 4, I congratulate Sen. Santorum and Gov. Romney on a hard-fought effort during the closest contest in caucus history," Strawn said.

The certified results: Santorum with 29,839 votes and Romney at 29,805, a difference of 34. Texas congressman Ron Paul finished third with 26,036.

The new numbers could give a boost to Santorum and other candidates trying to undermine Romney's dominance over the field as South Carolina primary voters go to the polls Saturday.