The five law lords unanimously overturned a high court decision in April that Tony Blair's government and the SFO caved in too readily to threats by Saudi Arabia over intelligence sharing and trade.

In today's ruling, the senior law lord, Lord Bingham, said the SFO's former director, Robert Wardle, was confronted by an "ugly and obviously unwelcome threat".

He said Wardle's decision to shelve the inquiry involved "no affront to the rule of law". Faced with threats of withdrawing anti-terrorism cooperation which could have put British lives at risk, "it may indeed be doubted whether a responsible decision-maker could …. have decided otherwise," Bingham said.

Another law lord, Baroness Hale, said: "I confess that I would have liked to be able to uphold the decision. It is extremely distasteful that an independent public official should feel himself obliged to give way to threats of any sort."

She acknowledged some would believe the inquiry was halted to protect British commercial interests, but she said "the evidence is quite clear that this was not so".

"Although I would wish that the world were a better place where honest and conscientious public servants were not put in impossible situations such as this, I agree that [the director's] decision was lawful."

The human rights director of the campaign group Justice, Eric Metcalfe, described the decision as "a bad day for the rule of law".

"The law lords have delivered a disappointingly narrow judgment. Justice is usually blindfolded but today she is hamstrung as well," he said.

The Campaign Against Arms Trade (CAAT) and the anti-corruption campaigners Corner House had sought a review of Wardle's decision to drop the investigation into allegations of bribery and corruption in the £43bn Al-Yamamah arms deal agreed by the Thatcher government in 1985.

The SFO was investigating allegations that BAE – one of the world's largest arms makers – ran a £60m "slush fund" and offered sweeteners to officials from Saudi Arabia in return for lucrative contracts.

In a strongly worded judgment, the high court ruled in April that the Saudi threat was a "successful attempt by a foreign government to pervert the course of justice in the United Kingdom."

Lord Justice Moses and Justice Sullivan said the SFO and the government had made an "abject surrender" to "blatant threats."

Today's judgment noted how Wardle resisted attempts to shelve the inquiry until late 2006.

It was only after meeting the British ambassador to Saudi Arabia, Sir Sherard Cowper-Coles, who warned of a grave danger to British citizens if the Saudis withdrew counter-terrorism cooperation, that he began to believe that the threat to British national security "might be so compelling that I would have no real alternative".

Bingham concluded that Wardle's judgment that the public interest in saving British lives outweighed the public interest in pursuing BAE to conviction was "courageous". He noted Wardle's concern that discontinuing the investigation "went against every instinct as a prosecutor".

CAAT spokesman Symon Hill said the case had eroded the public's trust in BAE and the government. Speaking outside the House of Lords, he said: "We feel we may have lost legally but we've certainly won politically."

In a hearing before the law lords earlier this month, Jonathan Sumption QC, representing the SFO, argued that Wardle made a legal and appropriate decision to stop the corruption inquiry in late 2006 after receiving threats from the Saudi Arabian government to withhold cooperation on critical issues of anti-terrorism.

"The SFO director was convinced that Saudi Arabia wasn't bluffing," he said.

Sumption told the Lords the high court made several incorrect assumptions about the law and the agency's actions, noting that some of the key evidence had been "redacted", or heavily edited, for security and diplomatic reasons.

"They proceeded on limited information available to them," Sumption said.

He criticised the high court for highlighting the alleged direct involvement of Saudi Prince Bandar bin Sultan, the former ambassador to the United States and now head of Saudi Arabia's national security council, in making the threats to drop a multibillion-pound Typhoon Eurofighter contract before the inquiry was halted.

"The director has not given evidence one way or the other about the involvement of Prince Bandar in the utterance of these threats." He said the threat came from "several channels over a period of time".