Media playback is unsupported on your device Media caption Mr Gingrich: ''I am appalled that you would begin a presidential debate on a topic like that''

US Republican presidential contender Newt Gingrich has angrily denied a report that he once wanted an "open marriage", strongly criticising the US media at the start of a key debate.

Mr Gingrich told CNN's debate host that even raising the issue was "as close to despicable as anything I can imagine".

He called the US media "destructive, vicious and negative".

The four remaining candidates appeared in a last-ditch debate before Saturday's South Carolina primary.

Mr Gingrich, Mitt Romney, Ron Paul and Rick Santorum debated in Charleston after a dramatic day.

As Mr Gingrich gained on Mr Romney in the polls, an ex-wife revealed in an interview he wanted an "open marriage".

Meanwhile, Texas Governor Rick Perry pulled out of the race and Iowa said a vote mix-up meant Mr Romney had not won its caucuses.

Mr Romney, a former Massachusetts governor, is the front-runner in the state-by-state race for the Republican Party's nomination to challenge Democratic President Barack Obama for the White House this November.

He is ahead of Mr Gingrich, a former speaker of the House of Representatives, Christian conservative former Senator Rick Santorum and Texas Congressman Ron Paul.

'Grandiose thoughts'

After Mr Gingrich's blistering opening, Mitt Romney's caution on the issue of his tax returns provided the most revealing moment.

Media playback is unsupported on your device Media caption Mr Romney: ''What I have, I earned. I worked hard, the American way''

Asked if he would follow his father's example and release 12 years of returns, Mr Romney - who is worth an estimated $200m (£130m) - said he would release "multiple years", but hesitated in his answer and drew jeers from the crowd.

"I'm not going to apologise for doing well," he said. "What I have, I earned."

Mr Gingrich, by contrast, was able to announce that his campaign had released his tax returns shortly before the debate began.

The candidates also clashed over healthcare and President Barack Obama's controversial reform law.

Mr Santorum said he doubted Mr Romney and Mr Gingrich would keep their promises to repeal the law, citing their previous support for similar legislation.

The former Pennsylvania senator said he had never supported the individual mandate, while Mr Gingrich and Mr Romney "played footsie with the left" on healthcare.

Analysis At the end of a day full of twists and turns, it was perhaps inevitable that one of those twists would explode at the latest Republican debate, here in South Carolina. Newt Gingrich thundered with anger when the debate moderator asked about his second wife's allegation that Mr Gingrich once asked her to tolerate an open marriage, so he could maintain an affair with the woman who went on to become his third wife. His rivals all diplomatically avoided the issue, conscious that the media is doing their work for them. Newt Gingrich has been enjoying a late surge in the polls here and seems to believe he can defeat the current Republican front runner, Mitt Romney. But in a state with large numbers of socially conservative evangelical voters, stories about a candidate's troubled private life can have an effect. The debate had other lively moments, as the candidates all tried to score some last-minute points, in front of a noisy audience. Polls open on Saturday morning. If Mitt Romney wins here, his eventual nomination will look more certain than ever.

Mr Santorum - who adopted a combative tone throughout the debate - also questioned Mr Gingrich's time as House speaker, a time when he was a close associate of his rival.

"Sometimes you have these worrisome moments," he said, warning that Mr Gingrich could "pop off" at any time, in an echo of Mr Romney's earlier attacks that he was "unreliable".

Mr Gingrich was unapologetic, casting himself as a "rebel" during his congressional days, and arguing that he helped Republicans win a majority in the 1990s.

"You're right. I think grandiose thoughts." Mr Gingrich said. "This is a grandiose country"

Perry bows out

Mr Gingrich took the debate stage hours before ABC News broadcast the full details of an interview with his second wife, Marianne.

Despite poll numbers showing him gaining on Mr Romney, the long-time front-runner, his pitch to South Carolina's largely conservative and Christian electorate looked to be under threat by her testimony.

In an excerpt of her remarks on ABC News' Nightline programme, the former Mrs Gingrich says her ex-husband wanted her to share him with Callista Bisek, the woman who would become his third wife.

"He was asking to have an open marriage and I refused," she said.

A dramatic day on the campaign trail began with the news that Texas Governor Rick Perry had decided to quit - and endorse Mr Gingrich.

Media playback is unsupported on your device Media caption Rick Perry: "I know when it's time to make a strategic retreat"

When Mr Perry entered the race in August, he briefly shot to the front of the pack before gaffes and poor debate performances set him back.

The Texas governor told supporters in South Carolina on Thursday: "I've come to the conclusion that there is no viable path forward for me in this 2012 campaign.

"Therefore today I am suspending my campaign and endorsing Newt Gingrich."

He called Mr Gingrich "a conservative visionary who can transform our country", adding: "Newt is not perfect, but who among us is?"

His departure follows on the heels of former Utah Governor Jon Huntsman, Minnesota Congresswoman Michele Bachmann and last month, Georgia businessman Herman Cain.

Mr Perry had faced calls in recent days to stand aside as rivals warned the conservative vote would fracture across the candidates, ultimately benefiting Mr Romney.

Thursday also saw the final results of the Iowa caucuses certified as a split decision between Mr Romney and Mr Santorum because of missing data.

Mr Romney had initially been declared the winner of the 3 January nominating contest, by a mere eight votes.

But the final count shows Mr Santorum ahead by 34 votes. No winner has been declared because the results from eight precincts are missing.