The prosecution of former Guantánamo inmate Moazzam Begg has dramatically collapsed after the police and crown prosecutors were handed secret intelligence material which undermined the terrorism case against him.

Five days before Begg was due to go on trial on a string of terrorism charges, prosecutors announced at the Old Bailey on Wednesday that they had “recently become aware of relevant material” which obliged them to offer no evidence.

The judge entered a formal verdict of not guilty and ordered that Begg be set free immediately from Belmarsh high security prison.

Police sources said the decision was taken following the receipt of intelligence material two months ago, and the Crown Prosecution Service said in a statement: “If we had been made aware of all of this information at the time of charging, we would not have charged.”

Asked whether the information had been handed over by MI5 and, if so, how long the agency had possessed the material, the Home Office said it would inappropriate to comment, on the grounds that the decision to halt the prosecution had been taken by the police and CPS.

Begg had spent more than seven months in custody after being arrested and questioned over a trip he had made to Syria a year earlier. His friends say that the experience had been deeply traumatic.

The 46-year-old from Birmingham was facing seven charges of possessing a document for the purposes of terrorism funding and training, and attending a terrorism training camp. He denied all the charges.

Christopher Hehir, prosecuting, told the Old Bailey that the CPS had previously been satisfied that they possessed sufficient evidence to secure Begg’s prosecution. He added, however: “The prosecution have recently become aware of relevant material, in the light of which, after careful and anxious consideration, the conclusion has been reached that there is no longer a realistic prospect of conviction in this case. The prosecution therefore offers no evidence.”

Begg’s solicitor, Gareth Peirce, said he should never have been charged as his activities did not amount to terrorism. “This is a good man trying to do the right thing in a very difficult world,” she said.

“He is a rare individual who will talk to everyone and listen to everyone, even those with whom he profoundly disagrees. He has spent the near decade since he was released from the torture of Bagram and Guantánamo in attempting to wake the world up to injustice and to comprehend its causes and effects. There is nothing new that can have been discovered now that was not always crystal clear – that this is an innocent man.”

Begg had made no secret of a trip he had made to Syria, at one point writing about his experiences in an internet post. He was taken aback by his arrest, protesting that he had not been engaged in terrorism.

On appearing in court, he denied attending a terrorist training camp “knowing or believing instruction or training was provided there for the purposes of terrorism” between 9 October 2012 and 9 April 2013.

He had also denied five charges of possessing articles for purposes connected with terrorism between 31 December 2012 and 26 February 2014. Those counts related to electronic documents found on a laptop computer in his possession.

Begg had further denied being involved in a funding arrangement between 14 July 2013 and 26 February 2014 by making available a Honda generator.

Had the case gone to trial, Begg was planning to argue before the jury that his actions – several months before the British government tried, and failed, to persuade parliament to sanction air strikes against Syrian government forces – were not the actions of a terrorist.

At an earlier hearing, his counsel, Ben Emmerson QC, defending, had told the court that his client’s stance on Syria was not at odds with the British government’s position. He said: “Mr Begg did not train anyone for the purposes of terrorism as defined in the 2001 act. Mr Begg says he was involved in training young men to defend civilians against war crimes by the Assad regime.

“This is not some sort of political defence. This is a serious point about the lethal and physical limits of the definition on terrorism because if the defence says the occasions concerned were defensive actions, in much the same way the UK was itself providing non-lethal aid itself, then we submit that would not be defined as an act of terrorism.”

Begg spent more than three years detained without charge after the al-Qaida attacks of 2001. In February 2002 he was arrested in Pakistan, handed over to US forces, and detained first at Bagram prison, north of Kabul, and then Guantánamo Bay. During his detention he was interrogated by British as well as US intelligence officers.

He was eventually released in January 2005. Working with the London-based rights group Cage, he became a prominent campaigner on behalf of terrorism suspects who were being denied basic legal rights.

Asim Qureshi, Cage’s research director, said on the collapse of Begg’s prosecution: “This has been a testing time for Moazzam, his family and the Muslim community. The criminalisation of virtually any Muslim that has been to Syria has only increased in intensity, while Cage has been attacked from every angle by a host of government agencies.

“We hope that Moazzam’s release is a sign that the government are now willing to adopt a more measured strategy in relation to anti-terrorism policy and avoid the attempt to criminalise all dissent and crush any organisation like Cage that stands up for the rule of law and justice.”

The Islamic Human Rights Commission chairman, Massoud Shadjareh, added: “As was widely suspected there seems to have been no basis for his arrest and it does seem that as a high-profile member of the Muslim community, Mr Begg was being made an example of in order to silence activists campaigning against draconian anti-terrorism laws.”

While West Midlands police and the CPS were not disclosing the exact nature of the new information, detectives and prosecutors were dismayed that it had not been made available to them earlier.

A CPS spokesperson said: “At the time that the charges against Mr Begg were authorised the CPS was satisfied, in accordance with the code for crown prosecutors, that there was sufficient evidence available to provide a realistic prospect of a conviction and that it was in the public interest to prosecute. However, in accordance with our continuing duty to review and working closely with the West Midlands counter-terrorism unit, we have been made aware of material previously not known to the police investigation that means that there is no longer a realistic prospect of conviction. If we had been made aware of all of this information at the time of charging, we would not have charged.”

West Midlands Assistant Chief Constable Marcus Beale said: “New material has recently been disclosed to police and CPS, which has a significant impact on key pieces of evidence that underpinned the prosecution’s case. Our criminal justice system – quite rightly – demands a very high standard of proof.

“I understand this is going to raise many questions. However, explaining what this newly revealed information is would mean discussing other aspects of the case which would be unfair and inappropriate as they are no longer going to be tested in court.

“From the beginning this case has challenged the relationship between West Midlands police and some of the communities we serve. I would like to reassure them and Mr Begg that at every stage of this investigation my officers acted in the best interests of the public and of justice.”

Last week two brothers from Yorkshire, Muhammed Saeed Ahmed, 21, and Muhammed Naeem Ahmed, 20, accused of plotting to attend a terrorism training camp in north Wales were formally acquitted at the Old Bailey after the CPS decided against proceeding with a retrial against them. A jury had earlier been unable to reach verdicts. They were given suspended sentences on lesser charges under Section 58 of the Terrorism Act of possessing a record of information likely to be of use to a person committing or preparing an act of terrorism.