Kuala Lumpur, Malaysia (CNN) -- A Malaysian court Monday found opposition leader Anwar Ibrahim not guilty of sodomizing a former male political aide, bringing an end to a politically charged trial and shaking up expectations for elections this year.
Anwar's supporters erupted into cheers in the court room as the judge announced the verdict, as his wife and six children tearfully hugged one another other.
"Justice has been done," Anwar said as he left the court building, walking into a crowd of camera-wielding journalists and supporters. "I feel I have been vindicated."
He said the ruling had reinvigorated the opposition's efforts to mount a strong challenge to the current Malaysian government in the elections.
Anwar repeatedly said he was innocent, saying the trial was an attempt by the government to end his political career -- an assertion it has consistently denied. He had expressed doubt that he would receive a fair trial.
"Malaysia has an independent judiciary and this verdict proves that the government does not hold sway over judges' decisions," said Rais Yatim, the information minister.
Investigators arrested Anwar in July 2008 -- four months after a loose coalition of opposition parties that he led won 82 of 222 parliamentary seats in elections. It was the second time in the country's history that the ruling party had failed to gain the two-thirds majority needed to amend the constitution.
With the government expected to call elections in the coming months, Anwar said he was ready to start campaigning again.
"We're working and I'm very optimistic," he said, reiterating his view that Malaysia is in need of political reform.
"The system is still blatantly authoritarian," he said.
Thousands of supporters gathered outside the court building Monday ahead of the announcement of the verdict. They started arriving in a nearby parking lot before sunrise, accompanied by a heavy police presence.
Adding to the tense atmosphere, three small explosions went off in the vicinity of the court complex after the verdict, a police spokesman said, adding that the cause was still being investigated.
Two people suffered minor injuries and were taken to hospital, the spokesman said.
Anwar had been on trial for nearly two years in the Kuala Lumpur High Court on allegations that he sodomized the former aide, Saiful Bukhari Azlan, in June 2008. Sodomy, even if consensual, is an offense punishable by up to 20 years of prison in Malaysia.
In delivering the decision, Justice Mohamad Zabidin Diah said it was not safe to rely on DNA evidence that had been cited in the trial -- semen taken from the aide's body that the prosecutor alleged was Anwar's -- since it could have been contaminated.
The court was not willing to give a guilty verdict based on uncorroborated evidence, the judge said.
Before the verdict, Anwar and his supporters had been pessimistic about how the trial would turn out.
Before the decision was announced, he said he had already got his belongings together in anticipation of a prison sentence.
The trial that ended Monday was the second time he faced sodomy charges.
He was the heir apparent to former Prime Minister Mahathir Mohamad until 1998, when he was sacked and charged with corruption and sodomy.
Anwar spent six years in prison after being convicted on corruption charges in 1999 and on sodomy charges involving his wife's former driver in 2000.
Malaysia's highest court overturned the sodomy conviction and ordered him released from prison in 2004. However, the corruption verdict was never lifted, barring him from running for political posts until 2008.