Greenwald was working at the time with the Guardian newspaper and other publications on articles about US and British spying, based on highly-classified data leaked by former US National Security Agency contractor Edward Snowden.
Miranda, a Brazilian citizen, was transporting some of the encrypted data -- including 58,000 British intelligence documents -- from Berlin to Rio de Janeiro when he was stopped while in transit at Heathrow on August 18, 2013.
Backed by a coalition of freedom of speech organisations, Miranda challenged his detention in the High Court, claiming it was unlawful and breached his human rights.
But three judges today rejected his appeal for a judicial review, a decision welcomed by British Home Secretary Theresa May and London's Metropolitan Police.
Also Read
Judge John Laws said the detention "was a proportionate measure in the circumstances".
He added: "Its objective was not only legitimate but very pressing".
"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."
But Miranda argued that the ruling emphasised the restrictions on freedom of the press in Britain, and vowed to appeal.