A journalist's partner held for nine hours at Heathrow under anti-terror laws has lost his High Court claim that he was detained unlawfully.
Brazilian David Miranda lives with writer Glenn Greenwald, who exposed secret information on US surveillance leaked by whistle-blower Edward Snowden.
Articles based on some of the Snowden material were published by The Guardian and other news publications, and one of the leading figures in writing those articles was Greenwald.
Lord Justice Laws, sitting with Mr Justice Ouseley and Mr Justice Openshaw, rejected Miranda's claim that his detention by police at the airport last August under Schedule 7 of the Terrorism Act 2000 was both unlawful and a breach of his human rights.
Miranda, 28, was in transit from Germany to Brazil when he was stopped at the airport, detained, questioned and searched by police under Schedule 7 of the Terrorism Act 2000.
He had nine items, including his laptop, mobile phone, memory cards and DVDs, taken from him while detained.
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.
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 fell properly within Schedule 7.
Steven Kovats QC argued on behalf of Home Secretary Theresa May that her national security duty to establish the nature of Miranda's activity was "consistent" with use by the police of Schedule 7.
Agreeing, Lord Justice Laws said the schedule was "capable of covering the publication or threatened publication… of stolen classified information which, if published, would reveal personal details of members of the armed forces or security and intelligence agencies, thereby endangering their lives…"
The Home Secretary welcomed the ruling, saying: "This judgment overwhelmingly supports the wholly proportionate action taken by the police in this case to protect national security.
"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.
"Although the courts have fully supported the use of Schedule 7 in this case, we constantly work to ensure that our counter-terrorism powers are effective and fair. That is why Parliament has recently approved further safeguards proposed by the Government for the use of this essential border and ports security power.
"The police and our intelligence agencies do a vital and difficult job protecting our lives and freedoms from terrorists, serious criminals and hostile states. Their job has been made much harder as a result of intelligence leaks."
In a statement published on Greenwald's new website, The Intercept, 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.
He added: "I'm of course not happy that a court has formally said that I was a legitimate terrorism suspect, but the days of the British Empire are long over, and this ruling will have no effect outside of the borders of this country.
"I'm convinced they've hurt their own country far more than me with this ruling, as it emphasises what the world already knows – the UK has contempt for basic press freedoms."
Also published on The Intercept, Greenwald said the UK had equated journalism with terrorism.
He 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.
"British officials have also repeatedly threatened criminal prosecution of everyone involved in this reporting, including Guardian journalists and editors."
He went on: "The UK Government routinely threatens newspapers with all sorts of sanctions for national security reporting it dislikes. Its Official State Secrets Act makes it incredibly easy to prosecute journalists and others for disclosing anything which political officials want to keep secret."
Greenwald added: "As we made clear along ago, the obvious objective of these attacks – to intimidate the journalists working on this story and deter future disclosures – will remain completely unfulfilled.
"Since David's detention and the destruction of the Guardian's computers, there have been a spate of top secret GCHQ documents reported on and published around the world, many of which, to their credit, have been published by the Guardian."
Senior national co-ordinator of counter-terrorism and Deputy Assistant Commissioner Helen Ball, of the Metropolitan Police, said: "This was a very important case that has attracted considerable public attention.
"Schedule 7 of the Terrorism Act 2000 is vital in helping to keep the public safe.
"We are pleased that the court's judgment states that 'the stop was lawful, it was also on the evidence, a pressing imperative in the interests of national security'.
"Some commentators have characterised the stop as an attack on journalistic freedom; this was never the case.
"The judgment is a clear vindication of the officers' conduct, demonstrating that they acted lawfully and in good faith throughout."
In a written ruling, Lord Justice Laws rejected submissions that the use of the anti-terror laws against Miranda was an "unjustified and disproportionate" interference with the right to "protection of journalistic expression".
The judge said Miranda was stopped so the material he was carrying could be examined and, if it was found to pose a threat, "to neutralise the effects of its release" or further dissemination.
"To that extent the stop was lawful.
"It was also, on the evidence, a pressing imperative in the interests of national security."
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".
The external hard drive taken from Miranda "contains approximately 58,000 highly classified UK intelligence documents", said the judge.
He declared: "I accept that the Schedule 7 stop constituted an indirect interference with press freedom, though no such interference was asserted by the claimant at the time.
"In my judgment, however, it is shown by compelling evidence to have been justified."
Email pged@pressgazette.co.uk to point out mistakes, provide story tips or send in a letter for publication on our "Letters Page" blog