COLUMBIA, S.C. (AP) — Over more than two decades, South Carolina voters forgave U.S. Rep. Mark Sanford for his quirkiness, his infidelity and his lies. But they could not forgive him for his criticism of President Donald Trump.

Sanford lost his first election ever Tuesday, beaten for the Republican nomination for another term in the coastal 1st District around Charleston by state Rep. Katie Arrington.

Less than three hours before the polls closed, Trump endorsed Arrington on his Twitter account with an especially personal shot at Sanford.

"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 wrote, referring to Sanford's trip to South America in 2009 to have an affair while his unknowing staff in the governor's office told reporters he was hiking the Appalachian Trail.

Sanford survived that public confession to the affair to win two more terms to the U.S. House. But Arrington made an issue of his criticism of the president, calling him a "Never Trumper."

One of her ads got personal too, saying "it's time for Mark Sanford to take a hike — for real this time."

After declaring victory Tuesday, Arrington asked Republicans to come together. And she reminded them who she thinks leads them: "We are the party of President Donald J. Trump."

Sanford won three terms for U.S. House in the 1990s, then two four-year terms as governor before the affair marred the end of his second term. He returned in 2013 and won a special election to his old U.S. House seat, holding on twice more.

Throughout his political career, Sanford has played up his outsider credentials — both in the U.S. House, where he supported a box to check on federal tax returns to put $3 toward the national debt, and as governor, bringing a pair of squealing pigs to the state House and Senate chamber to protest what he call pork spending.

But Arrington, who works for a defense contractor, has exploited that trait, pointing out Sanford's call for Trump to release his tax returns, his vote against Trump's border wall proposal, and his calling proposed tariffs on alumni and steel "an experiment with stupidity."

Sanford responded that he speaks his mind regardless of party and said he has shown over two decades he is a true conservative. In his remarks Tuesday night, he said: "I stand by every one of those decisions to disagree with the president."

Then there was the Twitter post just after 4 p.m. Tuesday. After attacking Sanford, the president backed Arrington.

"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 is a second U.S. House member from the South attacked by a challenger for criticizing Trump. In Alabama, U.S. Rep. Martha Roby is in a July 17 runoff against former congressman Bobby Bright. Roby said two years ago that Trump's 2005 lewd comments about women, captured on an "Access Hollywood" microphone, made him "unacceptable as a candidate for president."

Arrington will take on Joe Cunningham, a construction lawyer and yoga studio owner who won the Democratic nomination Tuesday.

The district, which includes Charleston and the southern coast, has not elected a Democrat since 1978.

___

Sign up for "Politics in Focus," a weekly newsletter showcasing the AP's best political reporting from across the United States leading up to the 2018 midterm elections: http://apne.ws/3Gzcraw.