The unexpected decision set off pandemonium at the Kuala Lumpur High Court where Anwar — a former deputy premier who was sacked in 1998 and jailed on earlier sodomy charges — was mobbed by jubilant family and friends.
"Thank God, justice has been served," Anwar told reporters in the courtroom after being cleared of sexual misconduct with a young male aide, charges he said were a conspiracy to cripple his resurgent opposition alliance.
An elated Anwar later told AFP he was now clear to focus on the prize he has sought since his shock ouster from the ruling party in 1998: consigning the governing Barisan Nasional coalition to history.
"Now that I am vindicated and freed, naturally I will work with my friends and… the coalition of opposition parties to ensure we can wrest control of Putrajaya (Malaysia’s administrative capital)," he said.
"Our only concern now is to ensure that the elections are held free and fair," Anwar said as he sipped milk tea in a festive atmosphere at his Kuala Lumpur home.
"Given free and fair elections, I am confident, God willing, we will win."
Thousands of supporters who had massed at the court under heavy security erupted into cheers and celebrated in the streets, shouting the opposition’s battle cry of "Reformasi!" (reform).
In a brief statement, Judge Mohamad Zabidin Diah said controversial DNA evidence submitted by the prosecution in the case was unreliable.
"The court is always reluctant to convict on sexual offences without corroborative evidence.
Therefore, the accused is acquitted and discharged," he said.
The ruling came as a surprise to many, including Anwar, who had said Prime Minister Najib Razak had fixed the verdict to remove him as a political threat and shore up the coalition’s five-decade grip on power.
Information Minister Rais Yatim said the ruling proved the sincerity of recent promises by Najib to do away with his coalition’s authoritarian ways.
"Malaysia has an independent judiciary and this verdict proves that the government does not hold sway over judges’ decisions," he said in a statement.
The United States hailed the acquittal, saying it was an opportunity for Malaysians to move forward.
"The ruling reflects favorably on the independence of Malaysia’s judiciary and presents an opportunity for all Malaysians to focus on the future," State Department spokeswoman Victoria Nuland said in a statement.
Najib faces a deadline of early next year to hold new polls in the ethnically diverse and resource-rich nation, in which he hopes to reverse unprecedented gains made by the opposition in 2008 elections.
But Anwar is now free to campaign at the helm of his opposition alliance — an unlikely marriage spanning Malaysia’s dominant Malay community, conservative Muslim forces, and the ethnic-Chinese and -Indian minorities.
The verdict throws the electoral landscape wide open, said Ibrahim Suffian, head of Malaysia’s leading polling firm Merdeka Center.
The outcome "vindicates Anwar and significantly removes doubts about his personal conduct, which has been a concern especially among conservative Muslim voters", Ibrahim said.
But he added that Najib can now also plausibly claim that his pledges of reforms to civil liberties — which the opposition has called an empty election ploy — are for real.
Anwar’s accuser, Mohamad Saiful Bukhari Azlan, said in his blog he accepted the court’s decision "with calmness."
Tensions spiked briefly outside the court as three small explosions took place.
Kuala Lumpur police chief Mohmad Salleh told AFP five people sustained "light injuries" but he declined to comment on what caused the blasts.
News of the acquittal electrified the crowds outside the courthouse, where hundreds of security personnel guarded the streets.
"All of a sudden he is free. I feel very excited. Finally he got justice," said jubilant hotel worker Shima Sharif, 46.
The charismatic Anwar had been groomed to succeed then prime minister Mahathir Mohamad until a bitter row between them forced Anwar out in 1998, and he was jailed on sodomy and graft charges widely seen as politically motivated.
He was freed in 2004 after the sodomy charge was overturned and assumed the leadership of the opposition, which seized control of five states and a third of parliamentary seats in the 2008 polls.
The new sodomy charges emerged shortly after, sparking accusations they were concocted by the government to stall the opposition revival.
Sodomy is illegal in Muslim-majority Malaysia and punishable by up to 20 years in jail.
After the ruling the European Union called for Malaysia to scrap its laws against homosexuality.