MI5 faced an unprecedented and damaging crisis tonight after one of the country's most senior judges found that the Security Service had failed to respect human rights, deliberately misled parliament, and had a "culture of suppression" that undermined government assurances about its conduct.

The condemnation, by Lord Neuberger, the master of the rolls, was drafted shortly before the foreign secretary, David Miliband, lost his long legal battle to suppress a seven-paragraph court document showing that MI5 officers were involved in the ill-treatment of a British resident, Binyam Mohamed.

Amid mounting calls for an independent inquiry into the affair, three of the country's most senior judges – Lord Judge, the lord chief justice, Sir Anthony May, president of the Queen's Bench Division, and Lord Neuberger – disclosed evidence of MI5's complicity in Mohamed's torture and unlawful interrogation by the US.

So severe were Neuberger's criticisms of MI5 that the government's leading lawyer in the case, Jonathan Sumption QC, privately wrote to the court asking him to reconsider his draft judgment before it was handed down.

The judges agreed but Sumption's letter, which refers to Neuberger's original comments, was made public after lawyers for Mohamed and media organisations, including the Guardian, intervened.

They argued that Neuberger had privately agreed with Sumption to remove his fierce criticisms without giving then the chance to contest the move.

In his letter, Sumption warned the judges that the criticism of MI5 would be seen by the public as statements by the court that the agency:

• Did not respect human rights.

• Had not renounced participation in "coercive interrogation" techniques.

• Deliberately misled MPs and peers on the intelligence and security committee, who are supposed to scrutinise its work.

• Had a "culture of suppression" in its dealings with Miliband and the court.

Sumption described Neuberger's observations in his draft judgment as "an exceptionally damaging criticism of the good faith of the Security Service as a whole".

His letter also refers to the MI5 officer known as Witness B, who is understood to have interrogated Binyam Mohamed in Pakistan in 2002. Witness B gave evidence in the hearings and is now at the centre of a Scotland Yard investigation. Sumption's letter implies that Neuberger did not believe that Witness B was acting alone and that the judge believed that Witness B's conduct was "characteristic of the service as a whole".

The court's final ruling forced the Foreign Office to publish a seven-paragraph summary of 42 classified CIA documents that were handed to MI5 before Witness B travelled to Pakistan to interrogate Mohamed. These show that MI5 was aware that Mohamed was being continuously deprived of sleep, threatened with rendition and subjected to previous interrogations that were causing him "significant mental stress and suffering". If administered in the UK, the summary says, it would clearly be in breach of undertakings about interrogation techniques made by the British government in 1972.

The three judges referred to a recent case in a US court where the judge found Mohamed's claims about how he was tortured to be truthful. This vindicated his assertion that "UK authorities had been involved in and facilitated the ill-treatment and torture to which he was subjected while under the control of the USA authorities".

There were renewed calls tonightfor an inquiry into MI5's involvement in torture overseas and into government policies after the 9/11 attacks.

Miliband told MPs that the ruling was leading to a "great deal of concern" in the US. In a statement to the Commons he said he had fought to prevent the release of the information to defend the "fundamental" principle that intelligence shared with the UK would be protected.

The Foreign Office claimed tonightthat the criticisms in the draft judgment had been "unsubstantiated", and denied that Sumption's approach to the court had been intended to suppress criticism of MI5. Nevertheless, the court is to convene tomorrow to reconsider whether to publish all or parts of the 21-line paragraph from the draft judgment in which the criticisms appear.

The editor of the Guardian, Alan Rusbridger, wrote to the court after the Sumption letter came to light on Monday night. He said today: "It is good news that – after a challenge from the Guardian and other news organisations – the courts have finally ordered the government to reveal evidence of MI5 complicity in torture. This is a watershed in open justice in an area in which it is notoriously difficult to shine a light. But it was extremely disturbing that the government's lawyers made a successful last-ditch attempt to get the master of the rolls to rewrite his judgment."

The government's lawyer, Jonathan Sumption QC, wrote a letter to the court of appeal on Monday in which he protested about the withering criticism of MI5 in the draft copy of the Binyam Mohamed judgment. Here we present the letter in full, annotated by the Guardian's Ian Cobain