Anti-terror powers were used to detain David Miranda, right, who was carrying 58,000 stolen secret documents through Heathrow airport on behalf of his partner Glenn Greenwald, leftPhoto: RICARDO MORAES/REUTERS

Secret MI5 memos warned police the partner of a Guardian journalist was carrying stolen spy information that would endanger lives and was designed to influence governments, it has been revealed.

David Miranda, whose boyfriend Glenn Greenwald was at the centre of the Edward Snowden intelligence exposes, was stopped at Heathrow airport last year with 58,000 secret files.

They contained highly sensitive information from the US National Security Agency and the UK’s GCHQ which were part of a cache of files stolen by Snowden, a CIA contractor.

A counter terrorism officer who sanctioned Mr Miranda’s detention said he feared the information could fall in to the hands of hostile states, such as Russia, or terrorist groups, the consequences of which would have been “catastrophic”.

The concerns were revealed as senior High Court judges rejected claims by Mr Miranda that he had been unlawfully detained under counter terror laws when held for nine hours last August.

His partner, Mr Greenwald, was the writer who exposed the secret information stolen by Mr Snowden in a series of articles published in the Guardian newspaper.

The revelations caused a political storm and led to accusations that the leaks had put national security at risk.

Mr Miranda, 28, was stopped on his way from Germany to Brazil on August 18 when police seized nine items, including his laptop, mobile phone, memory cards and DVDs.

In his ruling, the lead High Court judge, Lord Justice Laws detailed “port circulation sheets” that MI5 had sent to Metropolitan Police counter terrorism officers explaining why they wanted Mr Miranda stopped.

One read: “We assess that Miranda is knowingly carrying material, the release of which would endanger people’s lives.

“Additionally the disclosure, or threat of disclosure, is designed to influence a government, and is made for the purpose of promoting a political or ideological case.

“This therefore falls within the definition of terrorism and as such we request that the subject is examined under Schedule 7 (of the Terrorism Act 2000).”

Earlier memos warned the information would be “severely damaging to national security” and that Mr Miranda was suspected of “espionage activity”.

However all the memos stressed that Mr Miranda was not suspected of being involved in terrorist activity.

In a statement to the court, Detective Superintendent James Stokley said he sanctioned the stop because “the value of the material that (Mr Miranda) might be carrying to a hostile state … was enormous and its disclosure to agents of a hostile state … of a terrorist organisation … would be catastrophic.”

Lord Justice Laws echoed the claim of Andrew Parker, the Director General of MI5, that the leaked information was a “gift to the terrorist”.

He 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.

He 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 ..."

Theresa May, 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.

"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."

But 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.

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."

Mr Greenwald said the UK had equated journalism with terrorism.

"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.”

Rosie Brighouse, legal officer for Liberty, which intervened in the case, said: “If such a barefaced abuse of power is lawful then the law must change.”