Ministers have lost their court appeal against a ruling which said six control orders used against terror suspects broke European human rights laws.
Control orders are part of the anti-terrorism effort
Control orders are used where there is not enough evidence to prosecute.
The Court of Appeal upheld the decision made by a judge earlier this year that orders made against six suspects were too severe and should be quashed.
The orders, which kept the men inside for 18 hours a day, are being changed but the government is to appeal again.
The court did allow one part of Home Secretary John Reid's appeal against an earlier ruling which said another suspect had not been given a fair hearing when put on a control order.
'Over the line'
Earlier this year, Mr Justice Sullivan ruled that control orders on six suspects were so strict that they broke Article 5 of the European Convention on Human Rights, which outlaws indefinite detention without trial.
The six men, who cannot be identified, are all Iraqi nationals who were arrested under anti-terrorism laws and later released without charge.
Instead, control orders were made against them which forced them to stay indoors between 4pm and 10am every day.
There were other restrictions on who they could meet and they were banned from using mobile phones and the internet.
The appeal judges, headed by Lord Chief Justice Lord Phillips, said: "We agree that the facts of this case fall clearly on the wrong side of the dividing line.
"The orders amounted to a deprivation of liberty contrary to Article 5.
"We consider that the reasons given by Mr Justice Sullivan for quashing the orders are compelling."
The judges said the previous ruling had been right to focus on the fact that the six men were each confined to a small flat for 18 hours a day.
"Such a restriction makes most serious inroads on liberty, even giving that word its most narrow meaning," they said.
Responding to the judgement, Mr Reid said the court had made clear the terrorism laws themselves were in line with the European human rights laws.
But he promised to go to the House of Lords to appeal against the deprivation of liberty ruling because he was concerned about its impact on public safety.
"We are at a sustained high level of threat from a terrorist attack - put simply, an attack is highly likely," he said.
"Our security services are at full stretch and control orders form an essential part of our fight against terrorism."
Mr Reid said he had made new and amended control orders against the six suspects involved.
"Reluctantly amended, because these are not as stringent as the security services believe are necessary, but are required to maintain protection of the public to the best of our ability in this situation," he added.
The BBC has learned that the new control orders will mean the men have to stay in their flats for 14 hours a day, not 18 hours.
A rule saying all visitors to the men have to give advance notice in advance has been dropped, but some visitors are still banned.
Shadow home secretary David Davis said the court case was yet another example of government incompetence putting people's safety at risk.
The Conservative spokesman pointed to when previous measures allowing detention without trial had collapsed after another court judgement.
"We offered them an extension of those laws to allow time to come up with workable, robust effective new laws. They turned us down," said Mr Davis.