President Trump blindsided the international community and many of his own diplomats last week when he endorsed a Libyan military strongman whose forces are threatening the capital Tripoli.

But for years Gen. Khalifa Haftar, 75, was an American intelligence asset, plotting to overthrow Col. Moammar Gadhafi first from neighboring Chad and later from suburban Virginia with the support of the CIA.

The twists and turns in his career reflect the complexities of Libyan politics and the shifting patterns of influence since the 2011 uprising and the fall of Gadhafi.

Jeffrey Feltman, a former assistant secretary of state, told the Washington Examiner that Haftar had attracted support by posing as an anti-Islamist leader even though his own forces included hard-line Salafist elements. “That is antithetical to the anti-Islamist side he looks to play to the West,” he said. “He is not the savior he purports to be.”

Haftar was born in Ajdabiya, an eastern town along the coast road from Benghazi, and was among the small group of officers who seized power from King Idris in 1969. But he fell out of favor in the 1980s when he was captured fighting for Gadhafi’s army in neighboring Chad.

[Related: Trump praises Libyan warlord as his forces attack UN-backed government]

The Libyan leader denied any involvement in the conflict and ultimately disowned a man he later described in intimate terms. “He was my son and I was like his spiritual father,” Gadhafi told the Washington Post in 1992.

In Chad, Haftar won his freedom by joining a plot to bring down his former “spiritual father” and siding with the CIA-backed National Front for the Salvation of Libya. But he was out-maneuvered by Gadhafi. A Libyan-backed coup in Chad meant Haftar and his men had to be airlifted to safety by their American sponsors.

He eventually arrived in Northern Virginia where he was given U.S. citizenship and lived about a 20-minute drive from the CIA’s headquarters in Langley.

Friends quoted in several newspaper profiles said he had no discernible job or source of income but concentrated his energies on supporting an extended family. “They lived a very good life, and nobody knows what his source for compensation was,” an acquaintance said in 2014.

Property records show he lived with his family in the D.C. suburb of Falls Church until 2007. After that, they lived in a five-bedroom house in Vienna, a street away from the Westwood Country Club.

[Also read: Mueller report: Erik Prince's secret meeting with Russia fell apart after its aircraft carrier went to Libya]

He returned to Libya in 2011 hoping to take command of rebel forces after the uprising against Gadhafi. However, his ties to U.S. intelligence meant he was viewed with suspicion and had to settle for a supporting role.

That changed in February 2014, when he appeared on TV promising to restore security to a country shattered by war. “Operation Dignity” followed weeks later when he launched an assault on Islamist militants in Benghazi.

He was later recognized as army chief by the country’s eastern government. Since then his forces have taken control of the largest oil fields in Africa and are among rival groups vying for control of the war-torn country.

His efforts have won the support of Russia, Egypt, Saudi Arabia, and the United Arab Emirates, according to analysts. At the start of the month he ordered his Libyan National Army to advance on Tripoli, home of the internationally recognized government.

Diplomats at the United Nations have been working to agree to a United Kingdom-sponsored resolution calling for a ceasefire. They were taken by surprise on Friday when the White House revealed that Trump had telephoned Haftar days earlier, effectively reversing U.S. policy that called for armed groups to return to the political process.

"The President recognized Field Marshal Haftar’s significant role in fighting terrorism and securing Libya’s oil resources, and the two discussed a shared vision for Libya’s transition to a stable, democratic political system,” said the White House.

A senior Western diplomat said the president may have been influenced by his recent meeting with Egypt’s Abdel Fattah el-Sissi, a longtime supporter of Haftar and a booster of the general’s anti-Islamist agenda.

“Trump has a track record of being sympathetic to strongmen clamping down on dissent and tackling terrorism, so he would have been a willing recipient of that message,” he said, adding that efforts to agree a U.N. resolution continued.

But Feltman warned that White House backing may reduce chances of a ceasefire. “You had an opportunity to find a face-saving way out, with all sides recognizing this was not going to be easy and that a fight for Tripoli would have humanitarian consequences,” he said. “Instead we had the White House come out with a read-out that would likely embolden Haftar to keep fighting for Tripoli.”