She was the whistleblower who risked her freedom to try to prevent war. By leaking to the Observer details of a secret American dirty tricks campaign to spy on the UN before the invasion of Iraq, Katharine Gun hoped she could stir the public’s conscience, ratcheting up political pressure to the point that conflict could be avoided.

It was not, and Gun, then a 28-year-old working for GCHQ, the government’s eavesdropping centre in Cheltenham, was later charged with breaking the Official Secrets Act. The case against her, however, was abruptly and mysteriously dropped.

Now, before the release of a new film charting one of the most explosive episodes of the run-up to the invasion, the former director of public prosecutions has explained for the first time why he suddenly abandoned the case against Gun.

Sir Ken Macdonald told the Observer he had realised that it would be impossible to give the whistleblower a fair trial without also risking national security. Gun “could only get a fair trial if we disclosed material to the defence that would compromise national security,” he said.

Previously the government has said that the decision was taken “solely on legal grounds”, but failed to explain why the prosecution elected to offer no evidence during her trial.

Macdonald’s reference to secret material prompted calls for the documents to be declassified and the specific reason for dropping the case made public.

On Friday the film Official Secrets, starring Keira Knightley as Gun, opened in Los Angeles and New York, revealing to US audiences how Gun leaked the revelations in March 2003. Her actions prompted an international furore that saw her arrest and sacking. Macdonald then decided that she should face trial.

The film also strays into controversy by alleging that Macdonald paid a private visit to Ben Emmerson QC, who represented Gun, following the whistleblower’s arrest. During the visit, which according to the film occurred at Emmerson’s coastal Norfolk home, Macdonald is alleged to have told Emmerson that Gun had committed a “deliberate act of betrayal” and “should have kept her mouth shut”. In the film, Emmerson responds: “If you charge her, then I will defend her to the best of my ability.” Macdonald is understood to have denied that such a meeting took place.

The film, directed by Gavin Hood, suggests that the case against the GCHQ whistleblower was dropped in February 2014 because Gun’s defence team had asked for disclosure of the attorney general’s initial legal advice to Tony Blair before the invasion.

Abandoning the prosecution against Gun fuelled speculation that the case was dropped to spare the publication of the legal advice. It also left Gun demanding an explanation of why it took eight months after her arrest for her to be charged with breaching the Official Secrets Act.

But Macdonald has now categorically said that the decision to drop the case did not relate to the attorney general’s Iraq war advice.

This obsfuscatory statement from Lord Macdonald raises more questions than it answers Gavin Hood, director, Official Secrets

He said: “The case against her was subsequently discontinued because it became clear to me that she could only get a fair trial if we disclosed material to the defence that would compromise national security. I concluded that in the absence of this material being disclosed to her, her trial would be unfair, and so I terminated the case. This was my decision, which was notified to the AG [attorney general] in the usual way.”

The explanation, however, did not satisfy Hood, who spent three years researching and making the film and is known for the Helen Mirren thriller Eye in the Sky and the acclaimed South African crime drama Tsotsi.

“This obfuscatory statement from Lord Macdonald raises more questions than it answers. At the time, by denying Gun her day in court Macdonald and [attorney general Lord] Goldsmith effectively drew the shutters down over what Goldsmith’s legal advice to Blair had been in the run-up to war.”

Hood added: “But Macdonald now suggests that the case was not dropped because Goldsmith did not want his advice revealed. Rather he says there were other ‘national security’ reasons for doing so. If that is true, then one is compelled to ask when this material might be declassified and the real reasons for dropping the case made known to the public,” he added.

Martin Bright, the Observer journalist who received the leaked memo from Gun and was part of the team of reporters that broke the story, said: “Official Secrets raises serious questions about the treatment of Katharine Gun at the hands of the legal system. As the director of public prosecutions at the time, Lord Macdonald must take responsibility for this.”

The film, which opens in the UK next month, has led some critics to point out its relevance, eulogising the bravery of whistleblowers in an era characterised by disinformation and fake news.