The Metropolitan Police Commissioner has won an appeal against a High Court ruling over "kettling" tactics during the G20 demonstrations in 2009.
High Court judges declared that officers acted unlawfully in two respects during the protests.
But today Lord Neuberger, the Master of the Rolls, sitting in the Court of Appeal with Lord Justice Hughes and Lord Justice Sullivan, ruled that the High Court decision was flawed and allowed the police appeal.
The appeal decision is a blow to Hannah McClure, a student, and Josh Moos, a campaigner for Plane Stupid, who challenged the legality of the "violent" restraint methods used against them when they were contained by officers at the Camp for Climate Action in Bishopsgate in the City of London on April 1 2009.
Both now face heavy legal bills.
Moos said it was "a shame" the appeal judges could not see that the police were "out of control".
The day of the demonstrations was the day newspaper seller Ian Tomlinson died after being struck by a police officer at a separate G20 protest at the nearby Royal Exchange.
The police said the extended kettling was necessary to keep violent demonstrators at the Royal Exchange from "hijacking" the more peaceful climate camp, attended by up to 5,000 people.
The High Court ruled last April that there had been no evidence of an imminent breach of the peace to justify the kettle, when a tight police cordon was thrown round the climate camp demonstrators from just after 7pm for more than four hours.
The judges did not rule that kettling was unlawful but criticised "unduly inflexible" arrangements for releasing people. Moos said he became dehydrated after being refused permission to leave.
The judges also specifically condemned the police over the way officers armed with batons and riot shields "pushed north" a 15-deep crowd of demonstrators some 20-30 metres.
Sir Anthony May, president of the Queen's Bench Division, and Mr Justice Sweeney agreed that "unjustified force" had been used.
But today the appeal judges disagreed and ruled the police actions were not unlawful.
Lord Neuberger said the Commissioner's appeal was being allowed because the Divisional Court (High Court) had "applied the wrong test when assessing whether there was an imminent risk of breach of the peace".
Rather than assessing the "reasonableness" of the view taken by the officer in charge on the day, the judges had formed their own view.
"Even if they decided that (the officer's) view was unreasonable, there was no valid basis for reaching such a decision," said Lord Neuberger.
The decision to contain the substantial crowd of demonstrators at the climate camp and the police push were justifiable because of fears of the serious risk of them being joined by "dispersing demonstrators from another substantial crowd" which had been seriously violent and disorderly.
After today's judgment was handed down, Josh Moos, who had sought judicial review against the police, said: "This judgment won't make people forget the footage of the police baton charging the climate camp or what happened to Ian Tomlinson that day.
"The police acted violently and were out of control. It's a shame the judges couldn't see that."
Sam Walton, a member of the Camp for Climate Action legal team, said: "We are obviously disappointed with this conservative ruling and will be seeking to appeal.
"This had been one of the very few successful cases challenging the police's use of kettling and sent a clear signal that the tactics they used at the G20 were disproportionate."
Any new appeal will have to be made to the Supreme Court, the highest court in the land.
The appeal court judges refused permission, but it is still open to the demonstrators to argue that their case raises issues of general public importance which should be considered by the Supreme Court.
John Halford of Bindmans LLP, solicitor representing the protesters, said: "This judgment is very difficult to reconcile with the principle that the law protects peaceful protest and the stark facts of what the police did on 1 April 2009.
"The Supreme Court will be asked to examine the case.
"The police reaction to what the Court of Appeal has said is also very disturbing. There is no hint of contrition for the injuries protesters suffered at the hands of many officers involved.
"Instead there is merely the triumph of the known wrongdoer who has unexpectedly avoided censure for their actions."
Keith Vaz, chairman of the Commons Home Affairs Select Committee, said: "I welcome the verdict from the appeal court today.
"As the August riots and student protests highlighted last year, in order to appropriately respond to a situation of disorder, police must have available to them a wide array of tactics.
"The improper use of these tactics during incidents such as the G20 protests can seriously damage the public's faith in the police.
"In order to prevent this from happening again, the previous home affairs committee, in its report into the 2009 G20 protests, recommended that tactics such as containment should only be used sparingly and in clearly defined circumstances.
"What we now need is for clear parameters to be set so that those exercising their right to protest and police officers are aware of the situations in which these methods will be used."