In June 2013, Sen. Lindsey O. Graham faced a barrage of “RINO” criticism, disparaged as a Republican in name only who had just co-authored an “amnesty” immigration bill. South Carolina conservatives lined up to run against him in the primary.

And Rep. Mark Sanford, then newly sworn into a seat representing Charleston, began his second act in politics by returning to his rebellious conservative roots as a thorn in GOP leadership’s side.

Five years later, these two South Carolinians — close friends for almost 25 years — have completely reversed their roles. One is a regular confidant and golf partner of the most renegade Republican of all, President Trump, and the other is an outcast rejected by conservative voters for insufficient loyalty to Trump.

On Tuesday, Sanford found himself on the receiving end of an angry Trump tweet endorsing his opponent. On Thursday, Graham tweeted birthday greetings to the president, praising his golf game and including a picture of the two in the Oval Office with Graham flashing Trump’s trademark thumbs up.

Graham is on the rise, and Sanford is heading for the exits, having lost his primary Tuesday. The sky is yellow and the sun is blue.

Sen. Lindsey O. Graham (R-S.C.) arrives in the Capitol for Senate Republicans' meeting with President Trump on May 15 in Washington. (Bill Clark/CQ-Roll Call)

How did this happen?

“When you figure that one out, let me know,” Sanford said Friday in an interview, shaking his head.

Actually, he knows how it happened, and so does Graham. It’s all because of one person’s relationship with Republican voters, how Trump steered conservatives away from caring about policy outcomes and largely into emotion as ideology.

“I’ve been attacked for not being ideologically pure. Right? The head of our party is the least ideological person in the history of the Republican Party,” Graham said in an interview.

It’s a remarkable turn of events for two men whose careers have traced the arc of GOP politics for more than two decades.

One drifted in and out of conservative good graces, while the other stood pat and rose to national prominence, only to suffer international humiliation and come crawling back onto the public stage once again as an uncompromising conservative.

“I haven’t changed in the way I’ve approached politics. What I stand for has not changed. The party has,” Sanford said.

Graham suggested that his friend read the “tea leaves” wrong in recent years by becoming a strident Trump critic without offering positive reinforcement. He acknowledged that “there’s a lot to criticize,” from Trump’s overall demeanor to foreign policy positions that cut against conservative orthodoxy.

But, in his conversations with Trump, Graham said they discuss his public critiques of presidential decisions, as he also tries to steer Trump into a place of “how you fix it” rather than just “let’s burn it down.”

“It’s important for every president, but particularly him, to see that the critic actually can help,” Graham said.

Graham and Sanford both came to Congress after winning in 1994, part of the historic class that vaulted Republicans into the majority for the first time in 40 years. Graham was 39, Sanford was 34, and they were the vanguard of several dozen hard-charging freshmen.

“They came in — they’re gonna burn everything down,” Graham recalled of those early days and his lead role as unofficial spokesman for the rebels. “I was the loudest guy.”

Within a few years, they grew disillusioned with the uneven leadership of Newt Gingrich (R-Ga.) and plotted a failed coup attempt against the speaker.

In 1998, Graham served as an impeachment manager in the Senate trial of President Bill Clinton. Sanford actually lived up to his term-limit pledge, returning home to South Carolina and winning the governor’s race in 2002.

That same year, Graham won the Senate seat of Strom Thurmond, the staunch conservative icon, placing the two friends into prominent national positions.

But as Sanford steered a course as one of the most conservative governors, Graham became more of a bipartisan dealmaker, co-sponsoring the 2013 immigration legislation that would have created a path to citizenship for millions of undocumented immigrants.

In 2009 and 2010, Graham even voted for President Obama’s Supreme Court nominees. By 2014, he had to spend more than $5 million in the months leading up to his primary against six challengers, barely clearing the 50 percent threshold to avoid a runoff.

Sanford never wavered in his ideology. After Obama took office in 2009, some conservatives wanted him to challenge Obama in 2012 — then Sanford went on that “hike” along the Appalachian Trail.

He actually had flown to Argentina to meet his mistress, and by the time he was done explaining all this in a nationally televised news conference, he was left for dead politically. He staggered through his last months in office, and his divorce continued to create gossip fodder.

But in 2013, when his old House seat came open, Sanford jumped into a crowded GOP primary and won, only to see national Republicans pull away their resources. Graham did not join the exodus and was happy to see his old friend win the race.

They’re so close that Graham is godfather to Sanford’s youngest son.

In 2016, they had similar reactions to Trump, although Graham, as always, was the loudest. He told a large press dinner crowd that his party had gone “bats--- crazy” in backing Trump. Sanford was more cerebral, emerging from a closed-door meeting with Trump to question whether the nominee understood the Constitution.

But last summer, Graham started to see Trump’s ideological flexibility and tried to shape his decisions from the inside. “Ideology doesn’t drive this party like it used to,” explained Graham, who has a one-on-one meeting with Trump next week. “Can I say something? I think that’s a good thing, if we channel it to the middle.”

Sanford could never countenance such equivocation, not from a president with seemingly little grasp of core constitutional principles and conservative values.

“This is the Faustian bargain that’s going on right now: I’ll pander to you if you pander to me,” he said.

So he remained the conservative iconoclast until the end, losing to someone whose election night speech began with a simple declaration: “This is the party of Donald J. Trump.”

Sanford said he slept easy after defeat, particularly after his four sons delivered the same message: “Dad, we’re proud of you. If the principles you believe in cost you this, it’s much better to have lost.”

Read more from Paul Kane’s archive, follow him on Twitter or subscribe to his updates on Facebook.