The overthrow of Gaddafi has brought together strange allies, but few stranger than Abdulhakim Belhaj, the military commander of all rebel military forces in Tripoli, and Nato.

An Islamist whom Gaddafi tried to have the US list as a terrorist, Mr Belhaj says he was tortured by CIA agents after being arrested in the Far East in 2004 and later handed over by them to Colonel Gaddafi for further torture and imprisonment in Libya.

Mr Belhaj, the head of the military council for Tripoli, who led an Islamist guerrilla organisation fighting the Gaddafi regime in the 1990s, told The Independent in an interview that he had been directly "tortured by CIA agents" in Thailand after being first arrested in Malaysia.

If true, his story is evidence of the close co-operation between the CIA and Colonel Gaddafi's security services after the Libyan leader denounced the 9/11 attacks. After his stint in the hands of the CIA, Mr Belhaj was kept in Abu Salim prison in Tripoli. He says: "I was in prison for seven years during which I was subjected to torture as well as solitary confinement. I was even denied a shower for three years." Other Libyan Islamist prisoners have related how they were sometimes taken from Abu Salim to be questioned by US officials in Tripoli.

Released from prison in 2010, Mr Belhaj, who had military experience from fighting in Afghanistan against the Russians in the 1980s, became one of the most effective rebel military commanders. He is said by diplomats to have played a crucial role in the capture of Tripoli at the end of last month, and is highly regarded by the chairman of the Transitional National Council (TNC), Mustafa Abdul Jalil.

Ironically, given his claims of previous mistreatment at US hands, Mr Belhaj has emerged as one of Nato's most important allies during their air campaign in support of the rebels over the last six months. Speaking in his headquarters in the Mitiga military airbase on the eastern outskirts of Tripoli, he forcefully denied that he and the Libyan Islamic Fighting Group (LIFG), which he helped found in 1995, had ever been allied to al-Qa'ida.

"We never had any link to al-Qa'ida," said Mr Belhaj, a short, soft-spoken, bearded man, who does not use a military title. "We never took part in global jihad. The fact that we were in the same country, Afghanistan, [as al-Qa'ida] does not mean we had the same goal." He stresses that the sole aim of the LIFG was always to overthrow Gaddafi.

Despite his current close co-operation with Nato, Mr Belhaj says he finds it difficult to forgive his treatment by the CIA in the past.

When first detained at an airport in Malaysia in 2004 he says he was with his wife: "She was six months pregnant and she suffered a lot."

After a few days, CIA agents took him to Thailand as part of the notorious rendition process by which the agency transferred prisoners to countries where security forces were known to use torture. He says that in Thailand CIA agents took a direct part in his torture, though he did not give details. He says that "if I ever have the chance I will take legal action" against those responsible.

The disclosure of Libya's intelligence files may reveal embarrassing details of co-operation between the CIA and other Western intelligence agencies with Gaddafi's brutal and ruthless security services in pursuit of Islamist opponents. Mr Belhaj says that in the wake of 9/11, the US administration reacted by pursuing "any organisation with an Islamic agenda".

Mr Belhaj spent seven years in Abu Salim prison which was the site of the Gaddafi regime's most infamous atrocity, the massacre of some 1,200 prisoners in 1999, almost all of them Islamists, who had protested against conditions. The first protests which ushered in the uprising in Benghazi this February was by lawyers representing the families of the dead Abu Salim prisoners.

The Libyan prison was run with great savagery even against those whose offences were minor. Students accused of being excessively religious were stripped naked and attacked by dogs. Prisoners who survived might spend decades without seeing their families. In Abu Salim, Mr Belhaj helped write a 419-page document, published in 2009, which repudiated the Jihadi doctrine of holy war and the use of violence to change regimes. The name of the LIFG was changed to the Libyan Islamic Movement for Change. The ideological change, spurred by the failure of radical Islamic groups fighting on their own to overthrow governments, led to Islamists seeking the co-operation of more secular and liberal groups also opposed to Arab police states. It is these popular front coalitions that have won victories in Tunisia, Egypt and now Libya.

Mr Belhaj is keen to underline that he and other Islamists are not seeking to impose their agenda. He says: "The Libyan people have different views and those views will be respected." He also evidently wants to reassure Nato countries that they have not helped get rid of Gaddafi only to see a fundamentalist Islamic state replace him. He had just returned from a meeting in Doha, the capital of Qatar, which has given him significant support, where "I explained to them our vision of the future." Mustafa Abdul Jalil, chairman of the TNC, specifically says he was taken to a Nato meeting in order to reassure the West that he presented no threat.

Mr Belhaj says the thousands of militiamen from all over Libya, who owe allegiance to his Military Council, will ultimately join a new Libyan army or return to civilian life. Asked about mass round-ups of sub-Saharan Africans, often undocumented workers, accused of being mercenaries, he said he wanted harassment stopped, but many immigrants had no identity card. He added: "Last night 10 immigrants came to this base for protection and we will check their IDs and either look after them or help them leave the country."

On the whereabouts of Gaddafi, he said that the military operation room in charge of locating him had "strong information he is in Bani Walid". Saadi, one of Gaddafi's sons had phoned Mr Belhaj a few days ago "to separate himself from his father's regime" and was told that, if he surrendered himself, his safety would be guaranteed and he would receive a fair trial.

Belfast Telegraph