A journalist's partner held for nine hours at Heathrow under anti-terror laws has reacted angrily to a High Court decision that police and security services were legally justified in detaining him and examining material he was carrying.
Brazilian David Miranda immediately took steps to appeal against the ruling.
Lord Justice Laws, sitting in London with two other judges, rejected Mr Miranda's claim that human rights and press freedom were both victims of the disproportionate 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.
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 Mr Greenwald.
Mr Miranda said the court's ruling emphasised "what the world already knows - the UK has contempt for basic press freedoms".
His solicitor Gwendolen Morgan, from law firm Bindmans, confirmed he had applied for permission to appeal and said: "We look forward to the Court of Appeal considering the fundamentally important legal issues raised in our appeal in due course.
"Journalism is currently at risk of being conflated with terrorism. Therefore, our client has no option but to appeal."
A coalition of 10 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.
"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."
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 written ruling, supported by Mr Justice Ouseley and Mr Justice Openshaw, the judge rejected submissions that the use of the anti-terror laws against Mr Miranda was an "unjustified and disproportionate" interference with the right to "protection of journalistic expression".
In a decision being seen by investigative journalists as a serious threat to press freedom, the judge declared that Schedule 7 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..."
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."
Senior national co-ordinator of counter-terrorism 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."