One of Libya's senior rebel commanders has demanded an apology from the British and American governments following the discovery of secret documents which show MI6 and the CIA were involved in a plot that led to his capture and torture.
Abdul Hakim Belhaj, the security commander in Tripoli, told the Guardian he was considering suing over the episode, which raises further damaging questions over Britain's knowledge of the rendition and ill-treatment of prisoners.
One document found in a treasure trove of abandoned papers shows a senior MI6 officer boasting to the Libyans about how British intelligence led to Belhaj being captured on 6 March 2004.
Then a leading dissident member of the Libyan Islamic Fighting Group (LIFG), Belhaj was seized in Bangkok and handed over to the CIA, who he alleges tortured him and injected him with truth serum before flying him back to Tripoli for interrogation.
Documents show that five days before he was taken back to Tripoli, MI6 gave Libya Belhaj's French and Moroccan aliases, and told them he was in detention in Sepang, Malaysia.
Belhaj told the Guardian that British spies were among the first to interrogate him after he was returned to Tripoli, and that he was very "surprised that the British got involved in what was a very painful period in my life".
"I wasn't allowed a bath for three years and I didn't see the sun for one year," he told the Guardian. "They hung me from the wall and kept me in an isolation cell. I was regularly tortured."
Belhaj was released from the Libyan version of Abu Ghraib, Abu Selim prison, earlier this year after an amnesty announced by Gaddafi. He quickly took a lead role in the anti-government rebellion that ousted Gaddafi two weeks ago.
"This will not stop the new Libya having orderly relations with the United States and Britain," he said. "But it did not need to happen."
Scores of files, which were found abandoned at the British embassy and in the offices of senior members of the former regime, not only point to direct involvement of MI6 in this case, they also set out in sometimes excruciating detail how closely UK agencies were working with Libyan officials after Gaddafi came in from the diplomatic cold in 2004.
The papers also show how MI5 appeared to seek a trade of information about Libyan dissidents in London for morsels of intelligence gleaned from Tripoli – despite Libya's reputation for torturing prisoners.
Whitehall officials defended the links with Libya, saying the agencies were conducting themselves in line with "ministerially authorised government policy". But the material in Tripoli casts remarkable light on the capricious nature of intelligence work and the grubby deals that are struck in the name of national security – as well as raising disturbing questions about the UK's complicity in and knowledge of torture.
The Belhaj episode will be particularly discomforting for MI6, and may form part of a forthcoming inquiry chaired by Sir Peter Gibson, which is set to investigate the UK's role in rendition and the security services' knowledge of the torture and mistreatment of terrorist suspects.
The documents set out how MI6 believed it had played a crucial role in the capture of Belhaj seven years ago.
On Sunday he told the Guardian how he was tortured in Bangkok by two CIA agents, before being returned to Libya, where he was tortured again.
"I was injected with something, hung from a wall by my arms and legs and put in a container surrounded by ice," he said. "They did not let me sleep and there was noise all the time. And then they sent me to my enemy." Back in Libya, interrogators hung him from a wall every week and kept him in isolation for seven years.
MI6 knew of his whereabouts because Belhaj was attempting to seek asylum in the UK – information that British officials appear to have used to get him arrested.
The agency was interested in Belhaj because of his group's alleged links to al-Qaida – and the correspondence between the UK and Libya makes clear that MI6 wanted to ensure any information the Libyans gleaned from him went straight to Britain, and not through the Americans.
Referring to Belhaj by his nom de guerre, the MI6 officer, Mark Allen, sent a note to Moussa Koussa, then Gaddafi's head of external security, saying: "[His] information on the situation in this country is of urgent importance to us.
"Amusingly, we got a request from the Americans to channel requests for information from Abu Abd Allah through the Americans. I have no intention of doing any such thing. The intelligence about Abu Abd Allah was British."
The papers indicate that, in all, eight prisoners were captured and put on CIA "rendition" flights back to Libya during this period. They also reveal how MI5 sent a delegation to Tripoli in 2005, seemingly to cement relations at a time when one of the service's main concerns was the potential threat posed to British security by other dissident members of LIFG living in the UK.
One document, headed "UK/Libya eyes only", shows the security service gave the Libyans the names, personal details and addresses of 50 LIFG members living in the UK. One chart recovered from the British embassy identifies 17 LIFG members in London, Birmingham, Manchester and Wales. The information was being provided for "research and analysis purposes only".
In return, an MI5 report requested co-operation from the Libyans "to achieve our shared objectives".
"Such intelligence – particularly information relating to any financial transactions or to actual operational activity – is key to the security service working with the police to prosecute members of the group. The more timely information the better." MI5 said such intelligence could "shed important new light on current LIFG activities in the UK".
It would have been unthinkable for the UK to provide this kind of information to Libya in the 1980s – at the time, Gaddafi was running a covert assassination campaign to kill Libyan dissidents in Britain.
Whitehall officials defended MI5 on Monday, insisting that the security service had legitimate reason to seek information on LIFG members, because it believed the group had links with Islamic extremists – ties that were not severed until 2009. They said there was a potential threat to national security, and that in such circumstances agencies could not always pick and choose who they dealt with.
Nevertheless, it is quite possible that some of the dissidents reported on by MI5, like Belhaj, are now key members of the rebel forces that have toppled Gaddafi, and have been feted by the British government.
The foreign secretary, William Hague, tried to sidestep the controversy surrounding the documents, saying that they "relate to a period under the previous government, so I have no knowledge of those, of what was happening behind the scenes at that time".
However, Whitehall officials seemed perplexed by Hague's remarks, saying the coalition government had the same problems as those faced by Labour – how to deal with countries where torture and abuse was common, but that might still provide valuable information for British counter-terrorism efforts.
The Ministry of Defence was forced on the defensive too, after the papers showed that two of Gaddafi's sons were invited to visit the SAS headquarters in July 2006.
Khamis and Saadi Gaddafi were to see demonstrations of the work of the SAS and the SBS, and were then to be given confidential briefings by, among others, the chief of the defence staff, General Sir Michael Jackson. UK defence companies were also to be introduced to the two brothers. Though the trip did not go ahead, the efforts that the MoD were prepared to go to – at the behest of the government – will embarrass military officials who are now involved in the hunt for Gaddafi and his relatives.
By coincidence, the government's new anti-terrorist measures are to be debated in the Commons on Monday.
"When MPs vote in the Commons they should bear in mind we asked Libya for detainee briefs and the exchange of information on individuals," said Shami Chakrabarti, director of civil rights group Liberty. "There is no way the Gibson process, effectively an internal Cabinet Office one, can be adequate to deal with the unfolding scandal of this magnitude."