GREENVILLE, S.C. — Former House speaker Newt Gingrich (Ga.) won a stunning come-from-behind victory in the South Carolina presidential primary on Saturday, using hard-edged debate performances to vault over former Massachusetts governor Mitt Romney.

Gingrich was actually trailing Romney, in very early returns, after polls closed at 7 p.m.. But exit polls made it clear that he had defeated Romney — a win that will profoundly re-shape a nominating contest that, a week ago, seemed to be almost over.

Suddenly, Romney’s claim to be the GOP’s inevitable nominee looked dubious. Romney had arrived in South Carolina as the apparent winner of the first two GOP contests and faced an electorate that seemed open to his message that only a Washington outsider could restore free markets and sensible spending.

And yet he was beaten by a man who had been the ultimate Washington insider.

At the same time, the victory in South Carolina seemed to validate Gingrich’s new model for a presidential campaign — which held that his own strong debate performances could overcome Romney’s edge in advertising and money.

Here, it finally worked.

About two-thirds of South Carolina voters said that the debates — in which Gingrich blistered his opponents and the moderators — were an important factor in their decisions.

“The momentum as of tomorrow morning will be pretty decisive,” Gingrich told Fox Business News’s Neil Cavuto in a phone interview from South Carolina Saturday night. He said he looked forward to campaigning in Florida, where the next GOP primary will be held Jan. 31. “In the end, sooner or later, it’s going to become Romney versus Gingrich, and then the natural conservative Republican Party is going to repudiate a Massachusetts moderate whose actual record is, frankly, pretty liberal.”

Across South Carolina on Saturday, voters had said they liked Gingrich’s aggression in debates — believing it would make him the best Republican to take on President Obama in the fall.

“I think Mitt Romney is a good man,” said Harold Wade, 85, leaving a polling place in this picturesque seaside suburb outside Charleston. “But I think we’ve reached a point where we need someone who’s mean.”

That was Gingrich, he said.

“What we need is someone who’s got some brains,” Wade said, explaining his vote for the former speaker. “And we need someone with some guts.”

Other voters said they’d chosen Romney, inspired by his experience as a business executive, and his steady character. They said they’d been unperturbed by Romney’s troubles this week, as the candidate struggled to answer questions about his wealth and the release of his tax returns.

In Mount Pleasant, S.C., Michael and Elizabeth Ricciardone said they had decided long ago to vote for Romney and never wavered.

“It’s okay to be successful in this country. Redistribution of wealth is not in my vocabulary,” Michael Ricciardone said.

The dynamics of the race shifted in the last days before Saturday’s primary, with Gingrich surging after his aggressive performances in two televised debates.

A few weeks ago, in Iowa, Romney’s campaign and supporters had deflated a similar surge by Gingrich — using a series of negative ads to cast the former speaker as an erratic and self-defeating leader. But this time, Romney’s campaign did not attack Gingrich until the last days before the vote.

“I’d like to see what the report was that he provided to Freddie Mac,” Romney said Saturday, renewing an attack on Gingrich for his paid work for the controversial mortgage giant. “I’d like to see what he advised. He said he was an historian and just provided historical information, then he said he told them what they were doing was somehow not going to work. I’d like to see the report.”

It may have come too late.

“It’s kind of difficult this year. Everybody I talk to, they want to … they want a change from the president we got. They just don’t know which way to go,” said Danny Causey, who runs a neighborhood barbershop in Mount Pleasant, S.C. “Some of the ones they like the best, they think they don’t have a chance.” So Causey sensed a small shift toward Romney, despite all the hoopla for Gingrich.

Even before primary day began, strange things were happening in South Carolina. Just as light becomes distorted the closer it gets to a black hole, so does politics turn odd at the chaotic edge of an important primary.

On Friday night, for example, Romney — either as a sign of personal growth, or of exhaustion — finally located his zany inner comedian. He made a joke about the cheap Naugahyde office chairs that were used in the early days of Staples, the office supply giant that Romney helped launch.

“Killed a lot of Naugas to get these babies!” Romney said, part of an unusually animated stump speech. He was drawing a comparison to the upscale offices of executives at Solyndra, a failed solar-energy company that the Obama administration lent money to.

That joke itself was old enough to vote — in fact, since it originated in the 1960s, it’s old enough to run for president. But still, people laughed.

And on Saturday morning, like high-school rivals looking for a rumble, Romney and Gingrich both promised to show up in the same diner’s parking lot. In a state with 4.6 million people and 30,600 square miles, the two campaigns scheduled appearances at Tommy’s Country Ham House in Greenville, S.C., at 10:45 a.m.

In the end, Romney showed up 45 minutes early and was gone before Gingrich arrived. The former speaker couldn’t resist a little trash-talking: Gingrich emphasized his own Southern roots (and Romney’s Northern ones) by saying the diner offered some “good eatin’ ” and that it didn’t serve New England clam chowder.

“When we win tonight, we will launch the Florida campaign,” Gingrich said. “You start it here today. . . . I am the only conservative who has the opportunity to stop a Massachusetts moderate.”

The South Carolina race always matters: Since 1980, its winner has gone on to win the GOP nomination. But this year, it has taken on special importance: If Gingrich wins in South Carolina, it would deflate Romney’s air of inevitability. That would follow news, earlier this week, that former Pennsylvania senator Rick Santorum had actually won the Iowa caucuses — snatching away Romney’s slim lead in preliminary results.

Appearing increasingly confident as he campaigned Friday, Gingrich said that with the consolidation of the conservative vote, he could win “a shockingly big victory” Saturday. “The only effective conservative vote to stop the Massachusetts moderate is to vote for me,” he told an overflow rally in Orangeburg. “That’s what all the polls are saying now.”

Romney, recognizing the trend lines, began to lower expectations about the state’s primary and its effect on the GOP race. At his ham house appearance Saturday, Romney said he hoped to win Saturday’s primary here, but promised a long campaign regardless of the night’s outcome.

“We’re gonna work tirelessly to make sure we win this thing, not just here — we’d like to win here, of course — but we’ve got a long way to go,” Romney said. “So come join us in Florida and Nevada and Michigan, Colorado. . . . We need to get 1,150 delegates. We’re off to a good start. We’re gonna get more and more and more. With your help, I can become the nominee, and we can take America back.”

A Gingrich win in South Carolina would mean that, after three caucuses, there were three winners.

But, in the bigger sense, no winner.

Instead of crowning Romney as the inevitable favorite, the South Carolina contest would only set up the next primary, in Florida on Jan. 31.