Malaysian opposition leader Anwar Ibrahim has been acquitted of sodomy after a two-year trial.
Judge Zabidin Mohamad Diah said DNA evidence submitted by the prosecution was unreliable and discharged the case.
Mr Anwar, 64, has consistently denied the charges and called them a government bid to cripple his political ambitions and influence.
The government said the verdict showed Malaysia's judiciary was free from government influence.
Sodomy is illegal in Muslim-majority Malaysia but, says the BBC's Jennifer Pak in Kuala Lumpur, very few people are ever prosecuted.
'Justice has prevailed'
Mr Anwar had been accused of having sex with a former male aide. He had faced up to 20 years in prison if found guilty.
But the judge said that there were questions over whether DNA evidence had been contaminated.
"The court is always reluctant to convict on sexual offences without corroborative evidence. Therefore, the accused is acquitted and discharged," the judge said.
The verdict was greeted with cheers from Mr Anwar's supporters, wife and daughters, our correspondent says.
Mr Anwar told journalists outside the courtroom: "Thank God justice has prevailed I have been vindicated.
"To be honest, I am a little surprised."
Information Minister Rais Yatim said that the verdict showed that judges were free to rule as they saw fit.
"Malaysia has an independent judiciary," he said. "The current wave of bold democratic reforms introduced by Prime Minister Najib Razak will help extend this transparency to all areas of Malaysian life."
Police said two people were injured in two small blasts caused by explosive devices in a car park outside the court as the verdict was delivered. They did not say whether it was linked to the case.
The allegations against Mr Anwar surfaced just months after elections in 2008, in which he led the opposition to unprecedented gains at the expense of the ruling party.
This verdict comes ahead of elections due in 2013 but widely expected to be called later this year.
Hundreds of police and security personnel were on the streets of Kuala Lumpur ahead of the verdict, and thousands of Mr Anwar's supporters waited outside the court.
Mr Anwar was once Malaysia's deputy prime minister and an ally of former leader Mahathir Mohammad.
But he fell out with Mr Mahathir and was later jailed for corruption and sodomy. The sodomy conviction was later overturned and he was freed in 2004 after spending six years in prison.
He is now seen as the key figure in Malaysia's opposition coalition, which currently controls about a third of the seats in parliament.
The governing party has been in power for over 50 years and, says our correspondent, Mr Anwar is seen as the only person capable of challenging their dominance.
In a tweet from his account minutes after the verdict, the opposition leader looked ahead to the polls.
"In the coming election, voice of the people will be heard and this corrupt government will be toppled from its pedestals of power," the message read.