The ruling, which could have wider implications for the use of secret evidence, was described as a "historic" victory by the human rights lawyer Gareth Peirce. The home secretary, Alan Johnson, said he was "surprised and disappointed".

The two judges said it was "impossible" to conclude "that in bail cases a less stringent procedural standard is required [than in control order cases]".

They also rejected government claims that decisions by the Special Immigration Appeals Commission (SIAC), which deals with terror suspect cases, are immune from judicial review. Laws said judicial review was "a principal engine of the rule of law".

The ruling was a victory for a Pakistani student facing removal from the UK, who was refused bail on the basis of secret evidence, and an Algerian national, "U", whose bail was revoked.

He was later released by police, but immediately re-arrested and held pending deportation as a "threat to national security".

Jonathan Glasson, appearing for the home secretary, applied for permission to appeal, saying the case raised an "important point of principle". He said the ruling meant that XC and U, who were both considered to be risks to national security, could now be released on bail "notwithstanding the existence of closed evidence indicating that they might abscond".

The judges refused permission to appeal, but delayed the release of both men to give the SIAC time to ask the court of appeal itself to hear the case.

The case against XC hangs on MI5's interpretation of seven emails between him and an associate in Pakistan called Sohaib, who is said to be linked to al-Qaida.

In the emails, XC discusses a number of girls, called Huma, Nadia, Gulnaz and Fozia, and his plans for a "nikah", or wedding. MI5 suspects that the names are codes for ingredients for a bomb, and that the wedding refers to a planned attack.

XC's lawyers say this is a "far-fetched" interpretation of the emails, pointing out that no explosives have been found and that there is no forensic evidence to link him to any explosives. The SIAC said it was not satisfied MI5's assessment was "clearly wrong" – but it had reached this conclusion, in part, on the basis of secret evidence.

U is a 36-year-old Algerian who came to the UK to claim asylum in 1994. He spent time in Afghanistan after that, and it is claimed that he met Osama bin Laden there and helped to organise a terrorism training camp. He denies the accusations.

He was arrested at Heathrow in February 2001, and was to have been extradited to the US to stand trial for his alleged role in an al-Qaida plot to bomb Los Angeles airport, but the extradition request was later withdrawn.

U then spent more than seven years in British jails, without charge, before being freed in July last year under stringent bail conditions that prevented him from leaving his rented home or talking to visitors. He was rearrested after allegedly breaking his bail conditions.

Johnson said: "I am surprised and disappointed that the court has made this ruling. My sole objective is protecting the public, and this judgment will make that job harder.

"Both these suspected terrorists will remain in detention, following our arguments to the courts.

"I am seeking leave to appeal. We will do everything possible to keep this country safe and are taking steps accordingly in the light of this unhelpful judgment."

Peirce said: "The judges said there is an absolute, irreducible minimum of information that an individual should have."

She welcomed the court's "resounding no" to the idea that individuals could be detained on the basis of secret evidence, without recourse to apply to the high court for judicial review.

Shami Chakrabarti, the director of Liberty, said it had taken a senior judge "to point out what most people already know – if the government is going to lock you up, it needs to tell you why".

"Thanks to this historic judgment, the shadowy secret court system that has mushroomed under the 'war on terror' will now be exposed to the light of day," she said.

"The hard lesson of recent years is that diluting Britain's core values and abandoning justice makes us both less safe and free."

In June, the law lords ruled that it was unlawful to use "secret evidence" to place people under the control orders regime. But the ruling did not apply to the use of secret evidence to detain terrorist suspects without charge for deportation.