But Mr Ul Haque, then 20, had not finished the introductory training course, deciding the life of a jihadi was not for him. Once home, he had handed over his documents to the authorities and told them everything. For more than six months he had heard nothing. Now he was being told he was under investigation because an associate of his, Faheem Lodhi, was suspected of planning a terrorist attack in Sydney.

"You're in a substantial amount of trouble," the ASIO officer told him. "We have many means of investigation and hold considerable information about you. What we now require from you is your full co-operation." With these threats began a series of events that terrified Mr Ul Haque and, in the end, led to the case against him yesterday collapsing. It is the latest in a series of high-profile blunders by those responsible for prosecuting the war against terrorism. In a damning judgment, Justice Michael Adams said the two ASIO officers "committed the criminal offences of false imprisonment and kidnapping at common law".

Their conduct was "grossly improper", he said. Ruling all subsequent police records of interview inadmissible, Justice Adams also observed that the officers' later explanations for their behaviour were defensive and, at times, untruthful. "They were aware that what they were doing was unlawful. They were perfectly aware that they were not entitled to detain. Nor was there any suggestion of emergency that might have provided some mitigation for their conduct," he said.

ASIO had obtained a warrant to search the premises of the Ul Haque family on November 6, 2003. But the warrant did not permit them to detain Mr Ul Haque or question him. But the ASIO officers did so at Francis Park and at the Ul Haque home while it was being raided by 30 plainclothes officers. For almost 10 hours, he was detained, threatened and interrogated, with an Australian Federal Police officer taking notes on the side. Mr Ul Haque said the meaning of doing things the difficult way or the less difficult way was clear.

"I believed that I was under arrest and that if I did not comply with whatever they asked me that they will either use physical violence or take me to a more sinister place to interrogate me or, you know, do something to my family or deport me," he told the court. The initial ASIO raid and interrogations were followed up by interviews with the federal police. Mr Ul Haque said police told him his activities in Pakistan were not of concern, only his links to Lodhi.

In the ensuing weeks, it became clear what the authorities really wanted: they needed him to become an informant. If he did not co-operate and spy on Lodhi and suspected hot spots of extremist Islamic teaching, he would face serious consequences. "You wouldn't want to miss third-year medicine," one of the police officers told him. Mr Ul Haque rebuffed the overtures, which included the suggestion that he wear a covert listening device. "It's dangerous for me to go and do this thing," he told the police.

Four months or so after refusing to co-operate, Mr Ul Haque was arrested in April 2004 and charged with training with Lashkar-e-Taiba with the intention of causing harm to Indian armed forces. At the time he had trained with the group, it had not been proscribed by the Federal Government as a terrorist group.

In his judgment, Justice Adams said any alleged offence "was of relatively minor criminality. Indeed, I think that he did not know he was committing an offence under Australian law." The Director of Public Prosecutions abandoned the trial and the Attorney-General, Philip Ruddock, said any disciplinary action against the ASIO officers was a matter for the intelligence watchdog, Ian Carnell.