The government thought "British lives on British streets" would have been at risk if an arms deal inquiry had not been dropped, court documents show.
The claims were made at the start of a High Court challenge brought by the pressure groups Corner House Research and Campaign Against Arms Trade (CAAT).
The groups want to overturn a decision to halt a corruption inquiry into an arms deal between BAE and Saudi Arabia.
They claim that business rather than security reasons brought it to an end.
A lawyer for the groups argued that the decision had been influenced by hopes of winning new contracts.
BAE denies claims
BAE, the UK's largest defence group, has always said it acted lawfully.
The judicial review at the High Court in front of Lord Justice Moses and Mr Justice Irwin is expected to last for two days.
In the documents released to the court, Helen Garlick, assistant director of the Serious Fraud Office, was quoted as recalling what the Foreign Office told her about its fears of another bomb attack in the UK.
"If this caused another 7/7 how could we say that our investigation, which at this stage might or might not result in a successful prosecution was more important?," the notes quoted her as saying.
The Serious Fraud Office (SFO) had been examining whether BAE gave money to Saudi officials to help secure contracts in the 1980s.
The allegation investigated by the SFO centred on BAE's £43bn Al-Yamamah arms deal to Saudi Arabia in 1985, which provided Tornado and Hawk jets plus other military equipment.
BAE was accused of operating a slush fund to help it secure the contract.
The SFO inquiry into the Al Yamamah deal was stopped in December 2006, with attorney general Lord Goldsmith announcing that it was threatening the UK's national security.
Corner House and CAAT are trying to prove in court that hopes of winning a huge new arms contract from Saudi Arabia influenced officials.
Threats from members of the Saudi royal family to withdraw security and intelligence cooperation were also to blame, lawyers for the groups argue.
The SFO began its investigation into the Saudi arms deal in November 2004.
Documents released to the High Court showed that a year later BAE wrote letters to the Attorney General setting out the "reasons why the company considers it not to be in the public interest for the investigation to continue".
In one letter, BAE expressed concern that the disclosure of payments to agents and consultants involved in the deal would be seen by the Saudi Arabian government as a "serious breach of confidentiality by the company and the UK government".
It said this would "adversely and seriously" affect diplomatic relations between the UK and Saudi Arabian governments and "almost inevitably prevent the UK securing its largest export contract in the last decade".
Nicholas Hildyard, director of Corner House, said that the documents made it clear that national security, "the reason ultimately given for pulling the plug on this investigation", was used as a last resort.
"It was trotted out as a concern only when all these other special pleadings of commercial and diplomatic consequences had failed," he said.