High court orders publication of US report, saying British foreign secretary's actions were harmful to the rule of law

David Miliband, the foreign secretary, acted in a way that was harmful to the rule of law by suppressing evidence about what the government knew of the illegal treatment of Binyam Mohamed, a British resident who was held in a secret prison in Pakistan, the high court has ruled.

In a devastating judgment, two senior judges roundly dismissed the foreign secretary's claims that disclosing the evidence would harm national security and threaten the UK's vital intelligence-sharing arrangements with the US.

In what they described as an "unprecedented" and "exceptional" case, to which the Guardian is a party, they ordered the release of a seven-paragraph summary of what the CIA told British officials – and maybe ministers – about Ethiopian-born Mohamed before he was secretly interrogated by an MI5 officer in 2002.

"The suppression of reports of wrongdoing by officials in circumstances which cannot in any way affect national security is inimical to the rule of law," Lord Justice Thomas and Mr Justice Lloyd Jones ruled. "Championing the rule of law, not subordinating it, is the cornerstone of democracy."

The summary is a CIA account given to British intelligence "whilst [Mohamed] was held in Pakistan ... prior to his interview by an officer of the Security Service", the judges said. The officer, known only as Witness B, is being investigated by the Metropolitan police for "possible criminal wrongdoing".

The seven-page document will not be released until the result of an appeal is known. However, the judges made clear their anger at the position adopted by Miliband, MI5, and MI6 in their hard-hitting judgment.

An explanation was needed, they said, about "what the United Kingdom government actually knew about what was alleged to be cruel, inhuman or degrading treatment or torture, in particular what Witness B knew before he interviewed [Mohamed] ... in Pakistan". The judges added that it was important to explain what MI5 "and others knew when they provided further information to the United States to be used in the interrogation".

There was a "compelling public interest" to disclose what Miliband wanted to suppress, they said; there was nothing in the seven-paragraph summary that had anything remotely to do with "secret intelligence".

"In our view, as a court in the United Kingdom, a vital public interest requires, for reasons of democratic accountability and the rule of law in the United Kingdom, that a summary of the most important evidence relating to the involvement of the British security services in wrongdoing be placed in the public domain in the United Kingdom."

The judges sharply criticised the way Miliband and his lawyers tried to persuade the Obama administration to back the suppression of the CIA material. Lawyers acting for Mohamed, the Guardian and other media organisations pointed out that Obama had himself set up an inquiry into CIA practices and published details of their interrogation techniques.

In the end, Miliband had to rely for help on a CIA letter to MI6 claiming that disclosure of the document would harm the security of the US and UK.

The judges made it clear they did not believe the claim was credible. "The public interest in making the paragraphs public is overwhelming," they said.

The document would show what Witness B – an MI5 officer who interrogated Mohamed in Pakistan in 2002 – knew about Mohamed's condition before he questioned him incognito in a Pakistani jail, the judges said.

The CIA secretly flew Mohamed to Morocco, Afghanistan and then Guantánamo Bay, the court has heard. The judges criticised MI5 and MI6 for the belated disclosure of documents that revealed an MI5 officer was in Morocco when Mohamed was held there in a secret jail.

Miliband's lawyers continued to argue that a number of passages in the judges' ruling must be redacted as well as the seven-paragraph CIA document.

Jonathan Evans, the head of MI5, admitted in a speech at Bristol University on Thursday that the Security Service had been "slow to detect the emerging pattern of US practice in the period after 9/11".

"But it is important to recognise that we do not control what other countries do, that operational decisions have to be taken with the knowledge available, even if it is incomplete, and that when the emerging pattern of US policy was detected, necessary improvements were made."

He repeated the mantra that MI5 "does not torture people, nor do we collude in torture or solicit others to torture people on our behalf".

However, he said the situation posed a dilemma. "Given the pressing need to understand and uncover al-Qaida's plans, were we to deal, however circumspectly, with those security services who had experience of working against al-Qaida on their own territory, or were we to refuse to deal with them, accepting that in so doing we would be cutting off a potentially vital source of information that would prevent attacks in the west?

"In my view we would have been derelict in our duty if we had not worked, circumspectly, with overseas liaisons who were in a position to provide intelligence that could safeguard this country from attack. I have every confidence in the behaviour of my officers in what were difficult and, at times, dangerous circumstances".