Two Libyan terror suspects have won an appeal against deportation from the UK in a major defeat for the government.
Colonel Gaddafi agreed not to torture suspects
The men, known only as DD and AS, argued they could be jailed and tortured if sent home, despite a special deal between the countries.
But in the first test of the case, the Special Immigration Appeals Commission said the men could not be sent back.
The government said it was "very disappointed" by the defeat and would immediately appeal the ruling.
Under international human rights law, the UK does not deport people to regimes where they may face persecution or torture.
But in October 2005, the government signed an historic deal with Libya, under which Colonel Gaddafi's government pledged not to mistreat anyone deported to Tripoli from the UK.
Similar memorandums of understanding (MOU) have been signed with Jordan and Lebanon. A different diplomatic agreement is in place with Algeria covering the treatment of returnees.
But Mr Justice Ouseley, chairman of the Special Immigration Appeals Commission, the body that deals with deportation of terror suspects, said that the Libyan men faced a real risk of mistreatment.
The European Convention on Human Rights could be breached if the two men were removed to Libya, he said, although he indicated it was not a "probable risk".
"There is also real risk that the trial of the appellants would amount to a complete denial of a fair trial," he added.
FOREIGN SUSPECTS FACING DEPORTATION
Four have lost appeals
Three withdrawn appeals
Two won appeals
14 awaiting hearings or decisions
The two men, held in Long Lartin prison, have been granted bail in principle, with restrictive terms to be finalised.
In a statement, a Home Office spokesperson said they were "very disappointed" and it intended to appeal.
"We believe that the assurances given to us by the Libyans do provide effective safeguards for the proper treatment of individuals being returned and do ensure that their rights will be respected.
"These individuals have been found by SIAC to represent a real risk to the national security of this country."
The MOUs signed with Libya, Jordan and Lebanon are a key plank of the government's strategy to deport terrorism suspects it says it cannot put on trial in the UK.
The government had also been seeking to put in place independent monitoring of the welfare of any returnees to ensure Libya lived up to the deal.
According to the ruling, the nominated body is Libya's main human rights group, whose president is one of Colonel Gaddafi's sons. However, the government's own investigations into the body convinced officials that it was independent of the regime and capable of monitoring the welfare of returnees.
But in a statement, solicitors for DD and AS said: "It was common ground between the government and [our clients] that political opponents of the Gaddafi regime are reasonably likely to be tortured or otherwise ill-treated if returned to Libya."
Kate Allen of Amnesty International said: "Today's judgment underlines the principle that no one should be returned to a country where they may face torture. Memorandums of Understanding (MOUs) offer no protection from torture and are not worth the paper they're written on.
"If people are suspected of committing a crime, they should be charged and put on trial."