COLUMBIA, S.C. (AP) — By the end, Sen. John McCain had rejected President Donald Trump. The president was so infuriated by McCain he put a biting reference to the dying Republican senator in his stump speech. Yet one man in Washington still had hope for bridging the gap between the two.

"I regret that he didn't have more time with President Trump," Republican Sen. Lindsey Graham told The Associated Press this week about McCain, his late friend and mentor. Graham noted McCain was able to forgive his captors during the Vietnam War. "Who knows what would have happened over time?"

Graham's unexplained optimism, his eager attempts to soften Trump's rough edges, have confused colleagues and caused double-takes across Washington. The South Carolina Republican was McCain's best friend in the Senate, a self-described student of his politics and personal integrity. But he has deviated dramatically in his approach to the tempestuous and divisive president. While others stayed their distance — McCain perhaps most of all — Graham has gone all in, transforming himself into liaison, translator and, critics say, enabler of the president.

When establishment Republicans recently nodded knowingly at an anonymous editorial criticizing Trump's run of the White House, Graham was on Fox calling it a left-wing strategy to show Trump as "crazy" and echoed the president's unproven charge that the Russia probe "is falling apart."

The senator explains the shift from Never Trump to Team Trump largely in terms of responsibility. In an interview with the AP, Graham said McCain, who lost two bids for the White House, taught him that the country must move forward after elections. That means "you have an obligation" to help the president, especially a fellow Republican, he said. Graham says he's warmed to the president and suggests he's using that relationship to shape decisions — though he does not cite specifics.

"And I've tried to be helpful where I could because I think he needs all the help he can get," Graham said. "You can be a better critic when people understand that you're trying to help them be successful."

Graham has his own political motivations. His pivot comes as he is gearing up for his own re-election in 2020. The senator is popular in his deeply conservative state, but opposition to the president could mean risking a primary challenge.

"There's no doubt in my mind that the people of South Carolina, not just Republicans and independents, want to give this country a chance," Graham said. "The president won the state decisively. He's very popular among Republicans, and people want him to succeed."

Graham is hardly alone in facing a choice about how best to navigate the politics of the Trump era.

Some GOP lawmakers, like Sen. Jeff Flake and Sen. Bob Corker, have openly criticized Trump, to their own political detriment. Both are retiring. Others have been unabashed advocates of the president.

Then there are the former presidential rivals, Kentucky Sen. Rand Paul, Florida Sen. Marco Rubio — and now Graham — who have cozied up to Trump despite their campaign trail criticism, giving them a calling card to try to influence policy.

Like his mentor, McCain, Graham is the rare senator on Capitol Hill who likes to be in the mix on many issues, brokering deals with his quick wit and biting humor whether he's the expert or not.

Trump seems to agree. Graham has settled into the role of Trump whisperer, golfing regularly with the president and talking with him by phone. Graham's sphere of influence seems broad. When journalist Bob Woodward wanted to interview the president, he asked Graham to relay the message.

When Trump wanted to vent about Woodward's work, and leaks about a "resistance" within his administration, he talked to Graham about it.

"He's pissed off, he feels betrayed, and I don't blame him," Graham said.

Particularly in the national security realm, Graham, a defense hawk, provides an alternative to Trump's noninterventionist streak. In that way, Graham is upholding McCain's approach and countering another Trump whisperer, the libertarian-leaning senator Paul.

Because of Graham's relationship with Trump, the political world was jolted last month when he said the president may dismiss Attorney General Jeff Sessions after the election. It seemed as if Graham had inside knowledge of the decision, and it was an about-face from just last year, when Graham said Trump would have "holy hell to pay" if he fired Sessions.

There was a time when the Trump-Graham nexus of golf outings and White House lunches was inconceivable. Shortly after Trump launched his presidential bid in mid-2015, Graham called him a "jackass" who "shouldn't be commander-in-chief" for making disparaging remarks about McCain. Campaigning in Graham's home state a day later, Trump opened a rally by calling Graham a "lightweight" and "idiot" before reading out the senator's private cellphone number to the delight and disbelief of the crowd.

Graham ultimately abandoned his own presidential campaign and, along with McCain, opted not to attend the 2016 GOP convention. He said he wouldn't back either Trump or Democratic presidential nominee Hillary Clinton in the general election, saying the Republican Party had been "conned."

Graham acknowledged in the interview that Trump can "run hot" and "be a handful" at times. But he also says Trump listens and is more inquisitive than he gets credit for.

"Over time, through golf, I've actually gotten to know the person," Graham said, calling Trump both "charming and gracious."

Bob McAlister, a longtime South Carolina political communications strategist who has worked with Graham for decades, said Graham's approach to Trump reflects the senator's long-held beliefs about the consequences of elections, including McCain's 2008 loss to Barack Obama.

"Lindsey's message back then was, 'Elections have consequences,' and the Democrats cheered," McAlister said. "Today, Lindsey says, 'Elections have consequences,' and they try to cut his head off."

Brian Katulis, a senior fellow at the liberal Center for American Progress, says Graham has become "chameleon-like" as he courts Trump, trying to influence the president's thinking while getting little to show for it.

"So many people have tried to do that," Katulis said. "It simply doesn't happen."

___

Mascaro reported from Washington.

___

Follow on Twitter at http://twitter.com/megkinnardAP and http://twitter.com/lisamascaro