Rep. Mark Sanford of South Carolina, who lost his primary race this week hours after a last-minute Twitter broadside from President Donald Trump, warned his fellow Republicans on Thursday that the "question of allegiance" to Trump could damage the GOP.

"We swear an allegiance to the Constitution and we pledge allegiance to the flag and what was weird about this race that I've never experienced before in any race I've been a part of was an allegiance question where people say, 'Are you for or against the president?'" Sanford told MSNBC's "Morning Joe."

"I've never before had a question of allegiance to a person, rather than allegiance to the flag and Constitution, and to a degree that's what this race came down to," he added.

Sanford on Tuesday night lost to South Carolina state Rep. Katie Arrington, a political newcomer who spent much of the campaign blasting Sanford — who had never lost an election — over his lack of loyalty to Trump.

Trump got in on the attack, too, in a tweet on Tuesday, just hours before polls closed, that ripped Sanford's disagreements with the president and the lawmaker's much-publicized extramarital affair with an Argentinian journalist.

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. 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! — Donald J. Trump (@realDonaldTrump) June 12, 2018

On "Morning Joe," Sanford acknowledged that Trump's tweet hurt him but also discussed how the nature of the president's "if you offend me, I'm coming back to get you"-style of involvement in his race was "a little outside the norm."

Sanford admitted that the "traditional merit badges" of conservative values weren't a factor in the race and advised his fellow Republicans facing re-election on how best to avoid the president's ire during elections.

"Pledge allegiance to Donald Trump," he said.

Doing so, Sanford warned, could be "a mistake on a soul level."

"There are always trade-offs in politics," he said, "but I think everybody has got to answer that question for themselves."