MI5 colluded in the interrogation of a British resident held at Guantanamo Bay, the High Court has ruled.

Binyam Mohamed, an Ethiopian formerly living in London, faces the death penalty for allegedly plotting a radioactive "dirty bomb" attack on high-rise apartment buildings in the US.

He claims a confession being used against him in a military commission was extracted after he was subjected to secret rendition and torture.

The High Court said the role of the Security Service during the questioning of Binyam Mohamed in Pakistan went far beyond that of a by-stander.

Lord Justice Thomas said the court had concluded that the conduct of the Security Service "facilitated interviews by or on behalf of the United States when BM was being detained by the United States incommunicado and without access to a lawyer in Pakistan in the period April 2002 until at least 17 May 2002 when he was seen by an officer of the Security Service".

Under the law of Pakistan, he said, "that detention was unlawful".

The court also concluded "that the Security Service continued to facilitate the interviewing of BM by providing information and questions after 17 May 2002 in the knowledge of what was reported to them as to the circumstances of his detention and treatment in Pakistan".

The court said they continued to facilitate interviews by the US authorities after September 2002 when they knew Mr Mohamed was still incommunicado "and they must also have appreciated that he was not in a United States facility".

Lord Justice Thomas said: "By seeking to interview BM in the circumstances found in Pakistan and supplying information and questions for his interviews, the relationship between the United Kingdom and the United States authorities was far beyond that of a bystander or witness to the alleged wrongdoing."

MI5 was informed of Mohamed's arrest in Pakistan in April 2002 and the court heard they were interested in him because of his alleged connections with suspects in Britain, the period of time he had spent in Pakistan and Afghanistan, those he was said to have been with and the allegations made against him.

The judgment said: "The court has no doubt that on the basis of that information the Security Service were right to conclude that BM was a person of great potential significance and a serious potential threat to the national security of the United Kingdom."

A significant part of the recent hearing of Mohamed's application took place in closed session due to the national security sensitivity of much of the material before the court.

Lawyers for Binyam are seeking disclosure of information held by the British government but the court said it would not deliver a final ruling until it had the opportunity to consider the interests of national security.

The British government asked for the release of Mohamed and four other British residents who were not citizens in August last year but Mohamed was formally charged in June this year.

The evidence against Mohamed consists of confessions he made at Bagram, in Afghanistan, between May and September 2004 and at Guantanamo Bay before November 2004.

Mohamed claims that evidence is inadmissible because it was obtained as a result of a two-year period of incommunicado detention between April 2002 and May 2004 during which he was subjected to torture and cruel, inhuman or degrading treatment at the hands of the Pakistani and Moroccan authorities with the connivance of the United States government and to similar treatment by the United States government itself.

The former Kensington janitor, who is an Ethiopian national, alleges he was repeatedly slashed in the genitals with a razor blade while being held in Morocco.

Finally, he was rendered to Guantanamo Bay in Cuba where he has spent the last four years.

The charges allege Mohamed, who lived in London between 1994 and June 2001, then travelled to the al Faruq training camp in Afghanistan, to receive paramilitary training.

He was detained at Karachi airport on his way to the US via London where he was allegedly planning to launch his attacks.