Babies and ballots: This is what it looks like when SC votes

He's been known as South Carolina's political comeback kid, but his luck just ran out.

In a startling upset, U.S. Rep. Mark Sanford's re-election hopes were dashed Tuesday when he narrowly lost the GOP primary for South Carolina's 1st District congressional seat to Katie Arrington, a freshman state legislator from Dorchester County.

Before the race was called Tuesday, Sanford conceded before a crowd of his supporters, saying he's "always been a realist" and predicted he would lose once the final vote tally was in.

Though the race had not been officially called by AP or major networks, Arrington was maintaining a 51 to 46 percent lead with 86 percent of precincts reporting. They could meet again in a runoff if neither tops 50 percent.

Explore where you live.

"It says the Trump factor matters here," Kendra Stewart, a College of Charleston political science professor, said Tuesday night.

"In South Carolina, it's very unusual for an incumbent to lose a seat ... Almost more so than anywhere else, South Carolina likes to elect the known quantity, the person with the most name recognition. Going into this race, that was Mark Sanford."

Sanford's defeat also ends, at least for now, the political saga of a former governor who overcame personal scandal to reclaim a House seat he had given up years before. The race became a referendum on Trump’s popularity — a firestorm stoked by Trump himself — particularly in the final hours of the race in the Lowcountry district.

As voters went to the polls Tuesday, Trump took the extraordinary step of tweeting with advice to defeat an incumbent congressman from his own party. For Trump, it was payback for Sanford's often blunt criticism of his policies and rhetoric.

"Mark Sanford has been very unhelpful to me in my campaign to MAGA. He is MIA and nothing but trouble. He is better off in Argentina," the president tweeted. "I fully endorse Katie Arrington for Congress in SC, a state I love. She is tough on crime and will continue our fight to lower taxes. VOTE Katie!"

Sanford's exit from Congress marks the end of an era.

In recent years in Congress, Sanford has drawn ire from chamber-of-commerce Republicans for voting against omnibus spending bills containing money for the Charleston port deepening project — a top priority in his district — because he opposes earmarks.

But he also has softened some of his hardline stances.

For example, he has expressed support for a federal bank that loans money to international customers of U.S. businesses, including Boeing, the aircraft manufacturer with a plant in North Charleston, despite saying it flies in the face of his principles.

As S.C. governor, his rigid ideological conservatism made him a favorite of tea party Republicans while putting him at odds with state lawmakers over spending.

He famously brought two pigs into the State House in protest of what he saw as wasteful “pork” in the state budget.

He refused to accept $700 million in federal stimulus money aimed at helping struggling schools and was sued over it and forced by the S.C. Supreme Court to accept the money.

Sanford was rumored to be a potential presidential contender before his political career unraveled toward the end of his second term.

He was elected to the House again in 2013, and was a popular figure among colleagues.

Tuesday, Rep. Justin Amash, R-Mich., a member of the conservative House Freedom Caucus, had a stern answer to Trump's tweet.

"He's one of the most principled, consistent and conservative members of Congress I've ever known," tweeted Amash, one of the House's most outspoken conservatives. "And unlike you, Mark has shown humility in his role and a desire to be a better man than he was the day before."

Freedom Caucus Chairman Mark Meadows, R-N.C., said "I support Mark Sanford" before heading into an immigration meeting with House Republican leadership on Capitol Hill Tuesday afternoon.

By Tuesday night, Meadows was lamenting Sanford's fate. He hesitated to blame it on Trump.

"The people of South Carolina have spoken tonight," he said. "I think a tweet at the eleventh hour is not going to decide a race one way or another."

Arrington made Sanford’s disagreements with Trump a cornerstone of her campaign. She branded Sanford as a “Never Trump” Republican in name only who almost reflexively disagrees with the president.

“If Mark had gotten behind the president, the Affordable Care Act would be where it is today,” Arrington told McClatchy in January. “They (voters) see that very clearly and they want change…Absolutely, the surge for pro-Trumpness is growing and continues to get better every day.”