He said the stop was a disproportionate use of anti-terrorism powers and breached human rights law.
But judges ruled existing laws did not offer enough safeguards for reporters.
They said legislation, applied to ports such as Heathrow, "if used in respect of journalistic information or material", is incompatible with Article 10 of the European Convention on Human Rights - freedom of expression - and should be examined by Parliament.
Code of practice
Brazilian Mr Miranda is the partner of Glenn Greenwald, who had written a series of stories about spying. He was in transit from Germany to Brazil on 18 August 2013 when held at Heathrow for nine hours.
Mr Miranda was carrying encrypted material "derived from the data obtained by Mr Snowden", a former US National Security Agency contractor who has been granted temporary asylum in Russia. It included 58,000 highly-classified documents from the UK`s Government Communications Headquarters (GCHQ).
The High Court in February 2014 said the police action amounted to "indirect interference" with press freedom but this had to be balanced against national security considerations.
The Court of Appeal said the authorities had been justified in detaining Mr Miranda under Schedule 7 of the Terrorism Act 2000 .
"The police exercised the power for a permitted purpose. They were entitled to consider that material in his possession might be released in circumstances falling within the definition of terrorism," it said.
The Home Office maintains rules now in place give adequate protection to journalists, but lawyers for Mr Miranda say they do not go far enough and legislation is required.
A Home Office spokesman said: "We have always been clear that David Miranda`s examination by police under Schedule 7 was lawful and proportionate. The Court of Appeal`s judgment in this case supports the action taken by police to protect national security.
"In 2015 we changed the code of practice for examining officers to instruct them not to examine journalistic material at all. This goes above and beyond the court`s recommendations in this case."
Rosie Brighouse, from human rights group Liberty, said the judgement relating to police stops involving journalist material was a "major victory for the free press".
More about:






