Lord Justice Laws, sitting in London with two other judges, rejected Brazilian David Miranda’s claim that human rights and press freedom were both victims of the decision to detain him at the airport.
The judge said material being carried by Mr Miranda on an external hard drive included 58,000 highly classified UK intelligence documents that constituted “raw data stolen from GCHQ”.
The judge ruled there was “compelling evidence” that stopping and searching Mr Miranda was “imperative in the interests of national security”, even though there was “an indirect interference with press freedom”.
Mr Miranda, 28, is the partner of former Guardian writer Glenn Greenwald, who exposed secret information on US surveillance leaked by whistle-blower Edward Snowden. He is now taking steps to appeal against the ruling.
Mr Miranda said the court’s ruling emphasised “what the world already knows – the UK has contempt for basic press freedoms”.
A coalition of ten media and free speech organisations intervened in the case to express their concerns about the use of anti-terror powers against journalists.
Mr Greenwald said: “The UK government expressly argued that the release of the Snowden documents, which the free world calls ‘award-winning journalism’, is actually tantamount to ‘terrorism’ – the same theory now being used by the Egyptian military regime to prosecute Al-Jazeera journalists as terrorists.
“Congratulations to the UK government on the illustrious company it is once again keeping.”
But Home Secretary Theresa May welcomed the judgment and said it “overwhelmingly supports” action taken to protect national security.
She said: “If the police believe any individual is in possession of highly sensitive stolen information that would aid terrorism, then they should act. We are pleased that the court agrees.
Mr Miranda was detained by police at Heathrow airport last August under Schedule 7 of the Terrorism Act 2000 while he was in transit from Germany to Brazil. Nine items were taken from him, including his laptop, mobile phone, memory cards and DVDs.
Lord Justice Laws said it was plain that the purpose of stopping Mr Miranda “was to ascertain the nature of the material he was carrying” and to “neutralise” any threats it posed to national security. Thus it fell properly within Schedule 7.
The judge said Oliver Robbins, the UK’s deputy national security adviser at the Cabinet Office, had stated that “release or compromise of such data would be likely to cause very great damage to security interests and possible loss of life”.
In a statement published on Mr Greenwald’s new website, The Intercept, Mr Miranda said: “I will appeal this ruling, and keep appealing until the end; not because I care about what the British government calls me, but because the values of press freedom that are at stake are too important to do anything but fight until the end.”