Mitt Romney was running third in both states.
"We did it again," Santorum told cheering supporters in Lafayette, La. He said it was time for conservatives to unite in an effort to defeat Romney, the former Massachusetts governor who is the faraway leader in the competition for Republican National Convention delegates.
Romney bristled in the hours before the votes were counted, saying Santorum was "at the desperate end of his campaign."
But it was Gingrich with the most to lose as he struggled for political survival in a part of the country he hoped would fuel one more comeback in the unpredictable race to pick an opponent to President Barack Obama.
He congratulated Santorum on his victories, and poked at Romney. "If you're the front-runner and you keep coming in third, you're not much of a front-runner," he said in Birmingham, Ala.
In Alabama, with 76 percent of the precincts counted, Santorum was pulling 35 percent of the vote, Gingrich had 30 percent and Romney 28 percent.
Returns from 92 percent of Mississippi's precincts showed Santorum with 33 percent, Gingrich 31 percent and Romney 30.
Rep. Ron Paul, the fourth contender, made little effort in the states on the day's ballot.
There were 107 Republican National Convention delegates at stake on Tuesday, 47 in Alabama, 37 in Mississippi, 17 in Hawaii caucuses and six more in caucuses in American Samoa.
Evangelicals played an outsized role in both primary states, underscoring the challenge to Romney. In Mississippi and Alabama, 80 percent or more of voters leaving their polling places said they were born again Christians or evangelical. Those voters have been reluctant to rally to Romney's side in the primaries and caucuses to date. Among them, Santorum bested Romney by 9 points in Alabama and 4 points in Mississippi.
More broadly, the exit polls showed a primary electorate that was conservative, determinedly Republican and profoundly unhappy about the government.
In Mississippi, more than eight in 10 voters said they were dissatisfied or angry with the federal government, while in Alabama, 80 percent said they would definitely vote for the Republican candidate against Obama next fall, no matter who he is.
While Alabama and Mississippi are among the most conservative states in the country and share a long border, the exit polls showed significant differences in the voters' reaction to the candidates.
In Mississippi, Romney had the support of 30 percent of primary voters who earn under $50,000 a year, compared with 26 percent in Alabama. He drew the backing of 33 percent of Mississippi primary voters with no college education, compared with 27 percent in Alabama.
Only about half of all voters in each state said they work fulltime for pay, and they, too, voted differently one state from the other.
Santorum outpolled Romney, 39 percent to 23 percent among that group in Alabama. The two men tied among that group in Mississippi.
As has been true in earlier primaries, the economy was the most important issue to voters, and an ability to defeat Obama the most important quality when it came time to pick a candidate.
The exit polls were based on interviews with 1,552 voters as they left 30 randomly selected polling places around Alabama, and with 1,575 Mississippi voters from 30 sites. Each survey had a margin of sampling error of plus or minus 4 percentage points.
The Southern showdown came as new polling showed a decline in Obama's approval ratings - a reversal amid escalating gasoline prices and turbulence in the Middle East.
The day began with Romney leading the delegate competition by far in The Associated Press count, with 454 of the 1,144 needed to win the nomination. Santorum had 217, Gingrich 107 and Paul 47.
That gave the former Massachusetts governor more than his rivals combined. And while Santorum in particular challenges the mathematical projections, Romney is amassing delegates at a rate that puts him on track to clinch control of nomination before the convention next summer.
Romney, campaigning in Missouri, took exception to a television commercial airing in both Southern states and said Santorum "is at the desperate end of his campaign." The commercial was backed by a super PAC that supports the former senator, not by him.
Santorum's camp had earlier issued a memo that dismissed as fuzzy math Romney's claim that he is on track to amass a delegate majority. "Simply put, time is on our side," it said. Gingrich's aides issued a rebuttal of their own with the polls still open in the primary states. It said the primaries were not yet half over, and the former House speaker "is well positioned to win the GOP nomination."
The large amount of television advertising was testimony to the importance the contenders and their allies attached to the primaries in both Alabama and Mississippi.
All three candidates as well as super PACs supporting each of them ran television commercials. As has been the case all year, Restore Our Future, which backs Romney, spent more than any of the others. The group put down $1.3 million for television ads in Alabama, another $900,000 in Mississippi and more for radio on Christian and other radio stations as well as thousands of pieces of mail designed to help the former Massachusetts governor.
It was only in recent days that Romney seemed to sense a chance in Alabama and Mississippi, and he responded by increasing his television ad expenditures and his plans for campaigning in the states.
Born in Michigan and a longtime resident of Massachusetts, he told one audience the two primaries were "a bit of an away game for him" and drew laughs from another when he said he hoped to go hunting with an Alabama friend "who can actually show me which end of the rifle to shoot."
He generally steered away from criticizing his Republican rivals and aimed his rhetoric instead at Obama, whose prospects in both states are as dim next fall as anywhere in the country.
Santorum campaigned against the president and Romney simultaneously as he sought the support of conservatives who have fueled his recent surge.
In Biloxi, Miss., on Monday, he ridiculed the science behind global warming. "The dangers of carbon dioxide? Tell that to a plant, how dangerous carbon dioxide is," he said.
Gingrich spent part of his time pushing back against suggestions - including from his own staff - that he might drop out if he didn't notch a pair of Southern victories. His only two wins so far came in the South Carolina primary on Jan 21, and last week, when he won his political home state of Georgia.
Initial polls showed the former House speaker in a strong position in both states, but he abruptly canceled a campaign trip to Kansas in advance of the state's caucuses late last week to remain in the South.
He used a recorded telephone message from Chuck Norris, the actor and Karate champion, for a last-minute appeal to voters in Alabama.
Associated Press writers Charles Babington in St. Louis and Beth Fouhy and Philip Elliott in Montgomery, Ala., contributed to this report.