A Ugandan court has dropped all charges against opposition leader Kizza Besigye in connection with this year's cost of living protests.
He was arrested four times and accused of inciting violence during the protests, in which Ugandans were urged to walk to work.
On one occasion, he was beaten by police, sparking further protests.
Human rights groups condemned the suppression of the protests, in which at least nine people died.
Mr Besigye was defeated in February's presidential election but says it was rigged.
The government accused Mr Besigye of trying to organise an Egypt-style uprising and seeking to gain power through the streets after losing the election.
Magistrate George Wetyekere acquitted Mr Besigye of the three remaining charges - disobeying lawful orders, rioting after proclamation and incitement of violence.
Another charge of inciting violence had already been dropped.
The magistrate also stressed that the public had the right to hold public demonstrations.
After his release, Mr Besigye, said the charges had been brought against him for political reasons.
He also noted that before the previous elections, in 2006, he was charged with both treason and rape - and was later acquitted on both counts.
"I would like to once again condemn, in the strongest terms possible, the director of public prosecutions. Our country continues to be disgraced by that office's decisions," he told journalists outside court.
Mr Besigye sought medical treatment in Kenya after he was assaulted and sprayed with pepper spray in his car in April.
He was previously President Yoweri Museveni's personal doctor, but the pair fell out.
Mr Besigye left the country, saying his life was in danger, but returned in 2005 with the introduction of multi-party politics.