Judges decided that possessing Islamist videos and downloading jihadi propaganda did not mean that they were terrorists.
The Appeal Court ruled it was not enough to simply prove they had the material. It also had to be proved they intended to use it for terrorist acts.
Ad: Vacation? City Trip? Weekend Break? Book Skip-the-line tickets
Imran Khan, solicitor for one of the five, said: “Young Muslim men before this judgment could have been prosecuted simply for looking at any material on the basis that it might be connected in some way to terrorist purposes.”
But police and Crown Prosecution Service sources fear the ruling will allow impressionable youngsters to be exploited by Al Qaeda propagandists.
The five – one of whom ran away from home saying he was going to fight abroad – were jailed at the Old Bailey last year for a total of 13 years.
It was claimed they were planning to go to Pakistan for training before going to wage jihad, or holy war, in Afghanistan.
The court heard how searches of their computers unearthed material that would help them prepare to fight.
But yesterday, Lord Chief Justice Lord Phillips, sitting with two other judges at the Appeal Court, quashed their convictions and ordered their release.
Mohammed Raja, 20, of Ilford, East London, Awaab Iqbal, 20, Usman Malik, 22, both of Bradford, Aitzaz Zafar, 21, of Rochdale, and Akbar Butt, 21, of Southall, West London, were in court for the ruling.
At the heart of the decision was whether there was evidence that the men – four of them students at Bradford University – intended to use the material for terrorist purposes in contravention of section 57 of the 2000 Terrorism Act.
The judges ruled that the Act had in the past been interpreted too widely and used “for a purpose for which it was not intended”.
There have already been three other convictions under this legislation and more cases are expected before the courts this year.
Allowing the appeals, Lord Phillips said: “We do not consider that it was made plain to the jury, whether by the prosecution or by the Recorder, that the case that the appellants had to face was that they possessed the extremist material for use in the future to incite the commission of terrorist acts.
“We doubt whether the evidence supported such a case.”
He said the section of the law must no longer be given the wide scope it had been previously and must be given “a more restricted meaning”.
Malik’s solicitor, Saghir Hussein, said it was a landmark judgment.
“This will have implications for other cases, such as those alleging the glorification of terrorism,” he added.
Among the many terror cases that could be affected is that of “lyrical terrorist”, 23-year-old Samina Malik, also of Southall.
She was the first woman to be convicted under the Terrorism Act and was given a nine-month suspended sentence in December after being found guilty of owning terrorist manuals.
After the ruling, the judges were told that the prosecution was considering whether to appeal to the House of Lords.
They were also told that the Crown would not seek a retrial.
The release of the men opens the prospect that they could now seek damages for time spent behind bars.
All five had pleaded not guilty to possessing articles for terrorist purposes and said the material, downloaded from internet sites, was not intended to encourage terrorism or martyrdom.
But when sentencing last year, the Recorder of London, Judge Peter Beaumont, said they were preparing to train in Pakistan and then fight in Afghanistan where British soldiers serve.
Yesterday Lord Phillips said that the directions given to the jury by the judge were unsatisfactory.
Speaking after the ruling, solicitors for Butt said: “At the time of his arrest, he was a young and lawabiding man with a promising future and a career in medicine to look forward to.
“His reputation has been tarnished and his education unnecessarily interrupted by these proceedings. This young man and his family have been through a terrible ordeal.”
Interviewed on Channel Four news, Malik said: “I’m very happy, it has been two long years.
“I had it (the literature) for research purposes because I was inquisitive. You hear about stuff on the news and you want to find out for yourself. What I had was ideological material, not manuals or anything.”
When asked whether he believed in jihad, he said: “I prefer not to talk about my personal views.”
Security experts warned that the ruling could create a dangerous weakness in the law.
They said being able to curtail the activities of those drawn to dangerous extremist material is crucial in halting potential threats.
Patrick Mercer, a Tory MP and Government anti-terrorism adviser, said: “Surely this is how you identify the so-called clean skins.
“This very early indication of the potential for violence and radicalisation is exactly the sign for which we are looking. To give a stamp of semi-approval to looking at these sites is most odd.”
But Chris Huhne, LibDem home affairs spokesman, said “knee-jerk drafting of new terrorism offences” had led to the prosecutions.
“Ministers need to be more cautious when drafting new offences and more effective in enforcing old ones,” he said.
Whitehall sources last night played down the prospect of any of the men being placed under control orders to limit their movements.
Dr Ghayasudin Siddiqui, leader of the Muslim Parliament of Great Britain, said he hoped that the students’ experiences would serve as a warning.
He added: “It must go out to other young people that it is a dangerous area and they have to keep themselves far, far away from visiting these websites.”