Immediately after the 9/11 attacks, Tony Blair took a train from Brighton to London, where he issued a statement that pledged unswerving support for the US. He described terrorism as "the new evil in our world," perpetrated by people with no regard for the sanctity of human life. There was now to be a battle between the free world and terrorism, he said. "We therefore here in Britain stand shoulder to shoulder with our American friends in this hour of tragedy and we, like them, will not rest until this evil is driven from our world."

Quietly, Britain pledged logistics support for the rendition program, which resulted in the CIA’s Gulfstream V and other jets becoming frequent visitors to British airports en route to the agency’s secret prisons. Over the next four years, a 26-strong flight of rendition aircraft operated by the CIA used UK airports at least 210 times. Dozens of other private executive jets that the agency chartered were also regular visitors to the UK. Nineteen British airports and RAF bases were used, including Heathrow, Birmingham, Luton, Bournemouth and Belfast. The agency’s favorite destination was Prestwick in Scotland, which it used more than 75 times. One CIA pilot described Prestwick as an ideal refueling stop. "It’s an 'ask no questions' type of place, and you don’t need to give them any advance notice you’re coming."

The US authorities also asked the UK government for permission to build a large prison on Diego Garcia, the British territory in the Indian Ocean that operates as a US military base. A Royal Marines officer made some preliminary plans, before the project was dropped, for logistical rather than legal reasons. Diego Garcia continued to be used as a stopover for rendition flights, however, and senior United Nations officials believe that a number of prisoners were held and interrogated there between 2002 and 2003.

The UK would do more than offer mere logistics support to the rendition program, however. It would "perform," in Bush’s words, by becoming an enthusiastic participant in the rendition and torture program. As in the summer of 1940, its first victims would be British. But as then and since, Britain would enshroud its use of torture in the greatest possible secrecy.

In October 2001, when the United States and its allies went to war in Afghanistan to topple the Taliban regime that had harbored al-Qaida, it was inevitable that a small number of those captured on the battlefield would be British.

For more than a decade, MI5 had been aware that British Muslims had been traveling to Pakistan and Afghanistan to receive training at camps run by al-Qaida or associated groups. Pakistan’s main intelligence agency, the Directorate for Inter-Services Intelligence, or ISI, operated some of the camps, and graduates were encouraged to take up arms against Indian forces in Kashmir. Before al-Qaida began targeting the West in the late 1990s, MI5 saw these trips as evidence of little more than exuberant adventurism among a small section of young British Muslim males: a form of jihadi tourism that posed no threat to the UK. All that changed after 9/11, when both MI5 and MI6 became anxious to extract as much information as possible from any British prisoners in order to assess the al-Qaida threat.

It was not long before prisoners were being taken during battles in the north and southeast of Afghanistan. Many more foreign fighters were captured while attempting to slip across the border into Pakistan. Hundreds were handed over to US forces by Afghan and Pakistani bounty hunters, who received large bundles of dollars for every non-Afghan they captured.

Among the handful of British nationals seized in Afghanistan were Shafiq Rasul, Asif Iqbal and Rhuhel Ahmed. These men from the West Midlands, who became known as the Tipton Three, spent around a month in captivity in the north of the country before being flown to an interrogation center at Kandahar airport. By this time, the Red Cross was already complaining to US authorities about the systematic mistreatment prisoners suffered at Kandahar. On arrival all three were severely beaten. According to Iqbal:

An American came into the tent and shouted at me telling me I was al-Qaida. I said I was not involved in al-Qaida and did not support them. At this, he started to punch me violently and then, when he knocked me to the floor, started to kick me around my back and in my stomach. My face was swollen and cut as a result of this attack. The kicks to my back aggravated the injuries I had received from the soldier striking me with a rifle butt.

Another of the Britons who ended up in the Kandahar interrogation center was Jamal al-Harith. Born Ronald Fiddler in Manchester in 1966, al-Harith had converted to Islam in his 20s and had traveled widely in the Muslim world before arriving in Afghanistan. After 9/11 he had been imprisoned by the Taliban, who suspected him of being a British spy. At one point he and several other prisoners were forced to share their large cell with a horse that had offended a local Taliban leader in some ill-defined way. As bombs and missiles rained down on the city throughout October 2001, the unfortunate creature clattered around, terrifying its cellmates. A British journalist found al-Harith languishing in the prison in January 2002 and alerted British diplomats in Kabul, believing they would arrange his repatriation. Instead, they arranged for him to be detained by US forces, who took him straight to Kandahar.

A fifth Briton was Moazzam Begg, from Birmingham, who managed to escape from Afghanistan to Pakistan before being detained early in 2002. After being interrogated for several days by both British and American intelligence officers in a grand house in Islamabad, he begged one MI5 officer to get word to his family. "I can’t help you there," was the response. "I’m not a social worker." Begg was dispatched, hooded and shackled, to Kandahar, where he was beaten, stripped, shaved and photographed.

"I was past a state of shock. I couldn’t believe all this was happening to me. The noise was deafening: barking dogs, relentless verbal abuse, plane engines, electricity generators, and screams of pain from the other prisoners."

Back in London, government ministers and their intelligence advisers could not decide what to do with the young British Muslims being interrogated at Kandahar and at a second interrogation center US forces had established at Bagram airbase north of Kabul. One idea was to have them brought back the UK and prosecuted, possibly for treason. MI5 asked the Crown Prosecution Service whether they could "interview" the prisoners first and were told they could, as this would not inhibit any subsequent prosecutions.

In Washington, meanwhile, members of Bush’s war cabinet had decided that the expanded rendition program should result in the majority of prisoners being interrogated by the US military rather than overseas intelligence agencies. "The Department of Defense simply thought they could do it better than the Egyptians or whoever," says Mike Scheuer. They needed somewhere to carry out these interrogations and chose the Guantánamo Bay naval base on Cuba as the site for Camp X-Ray, a new maximum-security prison designed to hold hundreds of prisoners. The land had been leased in 1903 and was, in theory, on Cuban territory, thus putting the prison and its inmates outside the reach and protection of the US legal system. On Jan. 6, 2002, the first US combat engineers and contractors arrived at Guantánamo to begin construction. Three days later, senior lawyers at the US Justice Department drafted a memo that concluded the Geneva Conventions did not apply to al-Qaida fighters or members of the Taliban.

Twenty-four hours after the drafting of this memo, on January 10, British ministers had second thoughts about prosecuting British Muslims captured in Afghanistan. Government lawyers were warning that these men appeared not to have committed any offense under UK law and there was deep anxiety that the US government would be furious if they were brought back to the UK and subsequently released. Furthermore, police interviews in the UK would not be so effective as interrogations conducted overseas. So ministers decided, in the words of a secret Foreign Office memorandum, that their "preferred option" was the rendition of British nationals to Guantánamo.

Events moved rapidly. Later that day Jack Straw, the Foreign Secretary, issued a classified telegram to the British embassy in Washington and embassies across the Middle East. No objection should be raised to the transfer of the British nationals to Guantánamo, he ordered, as this was "the best way to meet our counter-terrorism objectives." He added, however, that their removal from Afghanistan should be delayed long enough to allow questioning by a "specialist team" of MI5 interrogators.

The first team of MI5 interrogators had arrived in Afghanistan the previous day, joining a number of MI6 officers who had entered the country at the end of 2001. The first interrogation was conducted at Bagram just as Straw was sending his telegram.

The makeshift prison at Bagram was located in a disused factory built during the Soviet occupation. There were discarded pieces of machinery scattered around the shop floor and notices in Russian hung on the walls. Concertina wire divided the building into pens. The interrogations took place in several offices on a first-floor landing.

By the time MI6 and MI5 officers first entered the prison there were 80-odd prisoners there, mostly Afghans and Arab fighters. A handful were British and it was immediately obvious they were being mistreated. Some of the prisoners were chained upright inside the pens, with hoods over their heads. Others were being beaten. One of the officers alerted his superiors that the first prisoner he questioned had been abused by the US military before the session began and the complaint was passed rapidly back to London.

The next day both MI6 and MI5 sent written guidance to all of their officers in Afghanistan. Covering two pages, these instructions had been prepared earlier in anticipation of such a complaint and were very carefully crafted.

This was the first sign that in the "war on terror" – the battle over "the ideas and values that would shape the 21st century," as Tony Blair put it – Britain and the US would stand shoulder to shoulder. Even when working the dark side. The guidance said:

You have commented on their treatment. It appears from your description that they may not be being treated in accordance with the appropriate standards. Given that they are not within our custody or control, the law does not require you to intervene to prevent this. That said, HMG’s stated commitment to human rights makes it important that the Americans understand that we cannot be party to such ill treatment nor can we be seen to condone it. In no case should they be coerced during or in conjunction with an SIS1 interview of them. If circumstances allow, you should consider drawing this to the attention of a suitably senior US official locally. It is important that you do not engage in any activity yourself that involves inhumane or degrading treatment of prisoners.

So MI5 and MI6 officers should not be seen to condone torture and must certainly not torture any prisoners themselves. But, crucially, they could continue to question people whom they knew were being tortured.

The door that could have been shut upon the use of torture during British operations against Islamist terrorism had been left open just a crack. A crack was all that was needed. Over the years to come, all manner of horrors would slip quietly through.

If the interrogations at Kandahar were brutal, those at Bagram were pitiless. At least two Afghans died under interrogation after being chained from the ceiling of their cells for several days while being beaten about the legs. Post-mortem examinations showed that their injuries were so severe that, had they survived, their legs would have had to be amputated.

There are allegations that British intelligence officers witnessed the abuse at Bagram and even took part on occasion, despite the warning that they must not be seen to condone it. Shaker Aamer, a Saudi who lived in London before traveling to Afghanistan, has given a statement to one of his lawyers in which he says British intelligence officers were present while Americans beat him and smashed his head against a wall. Hassan Zamiri, an Algerian married to a Canadian, has made a similar statement alleging that British intelligence officers interrogated him while he was being beaten and, on one occasion, waterboarded, and that one, an Englishman who called himself Paul, took part in the beatings. Moazzam Begg says he spoke not only to British intelligence officers at Bagram, but to visiting British soldiers.

Judging by the accounts that some of the inmates gave when they were finally set free, there is reason to believe that those conducting the interrogations were not just seeking intelligence. They were, as Cyril Cunningham, the in-house psychologist as the UK’s secretive Cold War organization A19, had put it, involved in the "selection, control and operation of secret agents and informers": the Bagram interrogators were hoping to turn some of the inmates – and doubtless, in some cases, they succeeded.

MI5 and MI6 officers conducted around 100 interrogations in Afghanistan over the next three years and the reports they subsequently sent to their superiors in London left no room for doubt about what was happening. After the interrogation in July 2002 of Omar Deghayes, a Libyan who had been living as a refugee in Britain, one of his questioners sent a detailed report back to MI5 headquarters. The report, which was disclosed during court proceedings brought by Deghayes eight years later, said: "The interview commenced at 1345 GMT and finished at 1600 GMT. Deghayes was brought to the interview room manacled and hooded. When the hood was removed, Deghayes looked pale and shaky. We asked if he was ill and he replied that he was suffering from malaria."

After offering Deghayes water and asking him whether he felt well enough to continue, the officers introduced themselves as Paul and Martin. They warned Deghayes that he was facing a long period of incarceration in US hands and that they would not consider helping him unless he told them everything they wanted to know. Deghayes was mumbling and incoherent at times. When he answered questions about links with jihadist organizations in Libya, the officers told him he was lying.

After another interrogation a week later, an MI5 officer reported back to London that Deghayes was thinner but alert. Deghayes said he was suffering internal bleeding:

He said the medical staff thought he was malingering and challenged us to explain how anyone could feign internal bleeding. Deghayes then launched into an extended complaint about why he was being held. No evidence had been presented yet he was still in custody. He was also being treated badly, with head-braces and lock-down positions being the order of the day. He was treated better by the Pakistanis; what kind of world was it where the Americans were more barbaric than the Pakistanis? We listened but did not comment.

MI5 decided that Deghayes should be sent to Guantánamo.

"If he sticks to his story and just gives a few more details, we propose disengaging and allowing events here to take their course," the officer wrote in his report to London. Deghayes was to spend more than five years at Guantánamo, where the abuse continued. At one point he was beaten so severely that he was blinded in one eye.

It is clear from the very small number of British government documents so far made public that ministers were informed about what was happening at the new US prisons within days of the decision being taken to consign British Muslims to Camp X-Ray.

On Jan. 14, 2002, four days after Straw sent his secret rendition telegram, a senior official attached to the Cabinet Office sent a six-page memo to David Manning, Blair’s foreign policy adviser, naming three British citizens held in Afghanistan and noting that they were "possibly being tortured" at a jail in Kabul. By January 18, at the latest, Blair had been made aware. The Prime Minister wrote by hand in the margins of one Foreign Office memo: "The key is to find out how they are being treated. Though I was initially skeptical about claims of torture, we must make it clear to the US that any such action would be totally unacceptable." Blair added a curious instruction to his officials: not to endeavour to stop the torture, but to "quickly establish that it isn’t happening."

Despite the Prime Minister being made aware of the possible use of torture, the UK remained a committed partner in the rendition program. All but two of the British citizens and residents who ended up in Guantánamo were sent there after Blair wrote his note. Documents later disclosed in court showed that after one British terrorism suspect, Martin Mubanga, was detained in Zambia, either Blair or someone close to him at Downing Street intervened to ensure that he could not escape rendition to Guantánamo. Mubanga denied any involvement in terrorism. Nevertheless, a reason for his rendition was set out in a note that Eliza Manningham-Buller of MI5 sent to John Gieve, the Permanent Secretary at the Home Office, which was also disclosed in court. "We are...faced with the prospect...of the return of a British citizen to the UK about whom we have serious concerns, whom it may be difficult to prosecute and whose release could trigger hostile US reaction," Manningham-Buller wrote.

Around the same time that British nationals were being packed off to Guantánamo, the euphemism "handling" was being coined at the highest levels of British government to describe the manner in which the prisoners were being treated. Straw’s secret telegram said it was for "the US authorities to determine the detail of how these prisoners should be handled. They have told us they would be treated humanely." Three months later, a senior Home Office official was noting, with evident relief, that on the matter of "handling," there had been "no press coverage here during the last four weeks."

The British government still had the option of bringing the young British Muslims back to the UK for prosecution. At the end of February, according to the minutes of a meeting of British security officials, the US was telling the British government that it could have all of the British detainees if it wished. But the officials concluded that the UK "should not be in any hurry" to take them. The representative from the Foreign Office was said to have remained quiet on this point, as his department had "some obvious problems of public presentation."

Some senior Foreign Office officials had severe misgivings about the manner in which events were proceeding. In a meeting with John Gieve in mid-April, Sir Michael Jay, Gieve’s opposite number at the Foreign Office, explained that his department wanted to press the Americans for legal access to the British at Guantánamo – "and wanted to be seen to be doing it." But, he explained, they had been overruled by Downing Street.

When the first batch of prisoners were flown from Afghanistan to Guantánamo, a few hours after Straw sent his secret telegram, they were wearing nappies, orange jumpsuits, handcuffs and shackles. They were also wearing blacked-out goggles, earmuffs and thick gloves, to ensure they experienced the sort of sensory deprivation that had been found to be so devastating during the three-way Canadian, American and British experiments of the 1950s. Such was the level of anger after the 9/11 attacks that the US authorities felt no shame about the way they were treating their prisoners: pictures showing the men being dragged across the ground were taken by US Navy photographers and distributed to the world’s media.

The US government was less candid about the principal purpose of Guantánamo, however. Defense Secretary Donald Rumsfeld said it was a place of detention where people who posed a threat could be kept from harming others. He even suggested that they were there for their own good, declaring a few days after Camp X-Ray opened for business that its inmates would be subjected to "appropriate restraint" as there were concerns that some might attempt to kill themselves.

In truth, Guantánamo was always an interrogation center, a place to which men could be consigned in order to squeeze from them every drop of intelligence that might possibly be of use. But while some of the inmates were undoubtedly dangerous terrorists – "bad people," as Bush called them – others were anything but.

A number of US Department of Defense documents leaked several years later showed that men were sometimes rounded up and taken to Guantánamo because the information they possessed was considered useful, rather than because they were thought to be dangerous. Said Abassi Rochan, for example, a 29-year-old Afghan taxi driver, was taken to Guantánamo to exploit his local knowledge. His file stated that he was "transferred to Guantánamo Bay detention facility because of his general knowledge of activities in the areas of Khowst and Kabul...as a result of his frequent travels through the region as a taxi driver."

The documents showed that Sami al-Hajj, a Sudanese cameraman for the al-Jazeera news network who had been detained on the Pakistan border while making his way into Afghanistan, was sent to Guantánamo "to provide information on...the al-Jazeera news network’s training program, telecommunications equipment, and news gathering operations in Chechnya, Kosovo and Afghanistan, including the network’s acquisition of a video of UBL [Osama bin Laden] and a subsequent interview with UBL."

The file of Jamal al-Harith, the man from Manchester who had been forced to share a Taliban prison cell with a horse, shows that he was sent to Guantánamo "because he was expected to have knowledge of Taliban treatment of prisoners and interrogation tactics." Eighteen months later, the camp authorities had satisfied themselves that he had no connection with the Taliban or al-Qaida, but decided against releasing him because his "timeline has not been fully established" and because British diplomats who had seen him in Kandahar had found him to be "cocky and evasive."

In all, nine British nationals were sent to Guantánamo, along with at least nine former British residents. All were incarcerated for years, and from the moment they arrived they suffered beatings, threats, sleep deprivation and other torments. All were interrogated by MI5 officers and some also by MI6.

Shafiq Rasul, one of the Tipton Three, says: "When we arrived at Camp X-Ray I was made to squat in the boiling heat outside for about six or seven hours altogether. I became desperate and eventually asked for some water. The soldiers realized I was English and a man from the Extreme Reaction Force came and started kicking me in the back and calling me a traitor."

Asif Iqbal says all his initial interrogations at Guantánamo were conducted by MI5 officers: "In my first interview with the MI5 official, I was told that I should say that I had gone to Afghanistan for jihad. He said that I did not need to say I’d been a fighter because there are lots of ways that one can do jihad."

When he and his friends denied this, they were told they would remain at Guantánamo for the rest of their lives.

Jamal al-Harith spent two years being kicked, punched, slapped, shackled in painful positions, subjected to extreme temperatures and deprived of sleep. He was refused adequate water supplies and fed on food with date markings 10 or 12 years old. On one occasion, he says, he was chained and severely beaten for refusing an injection. He estimates that he was interrogated around 80 times, usually by Americans but sometimes by British intelligence officers.

Al-Harith was finally released after more than two years. Nine months later he issued a statement in which he explained that he was still in pain as a result of the beatings he received before interrogation. "The irony is that when I was first told in Afghanistan that I would be in the custody of the Americans, I was relieved. I thought that I would then be properly dealt with and returned home without much delay."

MI5 and MI6 officers carried out around 100 interrogations at Guantánamo between early 2002 and the end of 2004.

Ian Cobain is an investigative reporter with the Guardian. His inquiries into the UK's involvement in torture since 9/11 have won a number of awards, including the Martha Gellhorn Prize and the Paul Foot Award for investigative journalism. He has also won several Amnesty International media awards.