Britain's counter-terrorism strategy was thrown into turmoil today when a judge ruled that two Pakistani students posed a serious threat to national security but could not be deported because of the risk they would be tortured or killed in their own country.

A special immigration court ruled that Abid Naseer was an al-Qaida operative who remained a serious threat, while his friend Ahmed Faraz Khan had been radicalised before coming to the UK and was willing to participate in terrorist activity.

Neither man was allowed to see the evidence upon which the court reached its decision, and nor was their solicitor. After they had been publicly identified as terrorism suspects, the court also ruled that it was not possible for them to be deported to Pakistan, where terrorism suspects face torture or death.

Mr Justice Mitting, chair of the Special Immigration Appeals Commission (Siac), said that in Pakistan "there is a long and well-documented history of disappearances, illegal detention and of the torture and ill-treatment of those detained, usually to produce information, a confession or compliance".

Theresa May, the home secretary, expressed disappointment at the ruling. She said: "We are now taking all possible measures to ensure they do not engage in terrorist activity."

Home Office ministers and senior security officials considering the implications of the ruling for Britain's counter-terrorism legislation. Since in law the two men cannot be jailed without trial, it appears certain they will be subjected to control orders – measures the Liberal Democrats condemned before the election as a "Kafkaesque" violation of the right to a fair trial.

Human rights groups say the judge's comments about Pakistani human rights abuses will make uncomfortable reading for senior figures in the last government, which encouraged Islamabad to detain and interrogate British citizens, using questions drawn up by British intelligence officers and police – a practice lawyers condemned as complicity in torture.

"Siac gave a clear nod to the authorities that if the [Pakistani] Inter-Services Intelligence stops torturing suspects then it would be possible to deport people to Pakistan. International co-operation has to be based on shared values, not just shared intelligence," said Shami Chakrabarti, the director of civil rights group Liberty.

The ruling also raises questions about the use of secret evidence. The men's solicitor, Gareth Peirce, condemned the decision as "the worst of all possible worlds", as they had been branded terrorists on the basis of material they could not see or challenge.

"It's no victory, even though the young men have won," Peirce said. "They have been stigmatised for life and put at risk or even further risk in their own country on the basis of the shocking phenomenon of secret evidence. It's no way to conduct justice. If people have committed a crime, put them on trial."

Naseer and Khan, both 23, were among 11 men, all but one Pakistani, arrested in April last year amid fears they were planning a bomb attack in Manchester. They came under suspicion because MI5 believed Naseer, a computing student at John Moores University in Liverpool, had links with al-Qaida, and that emails he sent, in which he mentioned a nikkah, or Muslim marriage contract, were a signal that an attack was imminent.

"Hi Buddy," one email read. "My mates are well and yes my affair with Nadia is soon turning in to family life. I met with Nadia family [sic] and we both parties have agreed to conduct the Nikkah after 15th and before 20th of this month."

The court accepted, from evidence heard in secret, that the recipient of the emails was an al-Qaida terrorist. "There is a longterm continuing threat [to Britain] and this is part of the narrative of that threat," a senior security source said.

The arrests were brought forward after the assistant commissioner, Bob Quick, the head of Scotland Yard's counter-terrorism command, was photographed in Downing Street clutching clearly visible secret documents revealing details of the investigation..

After being seized at addresses in Manchester, Liverpool and Clitheroe in Lancashire, the men were held for two weeks then released without charge. The 10 Pakistani nationals were immediately detained again on national security grounds.

After several months in prison, all but Naseer and Khan left the UK voluntarily, still protesting their innocence, and complaining the arrests had ruined their reputations and damaged their education.

After an inquiry, Lord Carlile, the terrorism legislation watchdog, said that none of the arrests had been made "on a full evidential foundation", and that "the authorities had no specific information as to where the suspected terrorist event was to occur, nor any precise knowledge as to its nature".

Some of the group had been arrested simply because they were associates of others, he said. But police were "probably right" to mount a large-scale operation, with gunpoint arrests in public places.

A third member of the group, Shoaib Khan, 31, who appealed against deportation after returning to Pakistan, won his case after the court said he was not a "knowing party" to Naseer's plans. Tariq ur Rehman, 39, and Abdul Wahab Khan, 27, lost appeals to return to the UK, with the court ruling they had been knowing participants.

Coalition watch: control orders

If the government were to resort to control orders to restrict the activities of the two men, it would represent a remarkable volte-face for the Liberal Democrat members of the coalition government: few other counter-terrorism measures have been so reviled by the party's leadership.

Speaking in 2007, for example, Nick Clegg, now deputy prime minister, asked : "How can it be right to impose what amounts to home detention without giving suspects any evidence for such a measure?" Two years later Clegg was warning that they represented "a slippery slope" that threatened to lead to further erosions of personal freedom. Last January, Chris Huhne, right, then the party's home affairs spokesman, fumed: "It is an affront to British justice and the freedom people have fought and died for to place people under de facto house arrest without even telling them why." Two months later Huhne condemned the orders as Kafkaesque, a bad dream and a nightmare, that were "a violation of fundamental rights and an expensive failure to boot".