Tony Blair's role in terminating a major corruption investigation was exposed today following the disclosure of Downing Street documents.

The papers reveal how Blair put enormous pressure on Lord Goldsmith, his attorney-general, to force him to put an end to the embarrassing investigation into a huge Saudi arms deal.

They also show that Goldsmith, nominally the independent head of the prosecution system, at first vainly tried to stop Blair interfering in the criminal investigation.

But Goldsmith then caved in and agreed to find a plausible justification for halting the investigation.

Blair's personal note to Goldsmith was disclosed in the High Court during a legal action brought by anti-corruption campaigners.

The campaigners are arguing that the decision to kill off the investigation was unlawful.

The legal challenge is being brought by the Corner House environmental group and the Campaign Against the Arms Trade.

The partly-sanitised documents show how Blair grew increasingly alarmed by the Serious Fraud Office investigation into allegations that BAE, Britain's biggest arms company, had paid massive bribes to Saudi princes to win lucrative contracts.

In 2006, two years after the investigation had been launched, the Saudis were threatening "repercussions" if the SFO investigation was allowed to proceed.

The SFO investigators were about to fly to Switzerland to gain access to bank accounts controlled by Saudi middleman Wafic Said, into which BAE had paid millions of pounds.

Blair's first attempt to end the investigation failed when Goldsmith stood firm. In a secret memo dated October 3 2006, Jonathan Jones, Goldsmith's chief of staff, told Gus O'Donnell, the cabinet secretary, that the "attorney is of the firm view that, if the case is in fact soundly-based, it would not be right to discontinue it on the basis that the consequences threatened by the Saudi representatives may result".

The Saudis stepped up their campaign to have the investigation stopped. During November, they delivered an ultimatum to Blair, telling him that they would suspend diplomatic ties with Britain unless the investigation ended.

On December 8, Blair wrote a "secret and personal" letter to Goldsmith in extremely strong terms demanding that he stop the investigation.

He said he was concerned about the "critical difficulty" in negotiations over a new Typhoon fighter sales contract, as well as a "real and immediate risk of a collapse in UK/Saudi security, intelligence and diplomatic co-operation."

"I am taking the exceptional step of writing to you myself" he said, because he thought he "would be failing in his duty" otherwise.

Blair said these were "extremely difficult and delicate issues" but he knew that constitutionally "any intervention you make ... must be your decision alone". Politicians normally have no right to interfere in a criminal case.

Goldsmith again attempted to resist. He saw Blair three days later and said, according to the official minute, that "While he was could see the force of the points in the prime minister's minute ... he was concerned that halting the investigation would send a bad message about the credibility of the law in this area, and look like giving in to threats."

Blair told him "higher considerations were at stake". He added: "Proceeding with the case would result in the end of Saudi-UK co-operation". Blair argued that this would endanger Britain's security as the Saudis would cut off the flow of intelligence about al-Qaida terrorists."

The minute of the meeting on December 11 also shows that Goldsmith suggested to Blair as an alternative that: "he felt justified in questioning whether the grounds for the investigation were soundly based and in exploring legal options for resolving the case as quickly as possible."

Within three days, on December 14, Goldsmith rose in the House of Lords to announce that the investigation had been terminated.

In those three days, he had examined the key evidence uncovered by the SFO investigators and claimed that a successful prosecution was unlikely.

The documents also show that the prime minister also personally vetoed a proposal that BAE could plead guilty to more limited corruption charges, saying this would "be unlikely to reduce the offence caused to the Saudi royal family."