Mr Anwar has called the charges part of a political smear campaign
Profile: Anwar Ibrahim
Rally against Malaysia vote outcome
Anwar urges Malaysia polls protest
A Malaysian court has sentenced opposition leader Anwar Ibrahim to five years in jail after overturning his acquittal on sodomy charges.
Mr Anwar led the opposition to its strongest ever performance in the May 2013 general elections.
While homosexual acts are illegal in Muslim-majority Malaysia, very few people are ever prosecuted.
Mr Anwar has always maintained the charges were part of a political smear campaign.
TIMELINE: ANWAR IBRAHIM
1993 to 1998 - Deputy Prime Minister, under Prime Minister Mahathir bin Mohamad
1999 - Jailed for abuse of power, sparking huge street protests
2000 - Found guilty of sodomy with his wife's driver
2004 - Supreme Court overturns sodomy conviction, freeing him from jail. He quickly emerges as the de facto opposition leader
March 2008 - ruling coalition narrowly wins general election, but with its worst results in 50 years. The opposition makes unprecedented gains
Aug 2008 - Anwar charged with sodomy for a second time, but despite this is soon voted in as an MP
Feb 2009 - Second trial for sodomy starts
Jan 2012 - Acquitted of sodomy by High Court
May 2013: Leads opposition to best-ever performance in general elections
Mar 2014: 2012 acquittal overturned by court after government appeal
The court decision will affect Mr Anwar's plans to compete in a key by-election in the state of Selangor this month, reports say.
A victory for Mr Anwar would mean he could become Selangor's chief minister - widely seen as a powerful post.
The court said he could remain free on bail while he appeals against the verdict to the country's highest court, AP news agency reported.
"All over again, after 15 years, they want to put me in the lockup and that is why they are rushing," Mr Anwar said after his acquittal was overturned.
He added that Prime Minister Najib Razak's government "faces the wrath of the people".
Meanwhile, a government spokesman said: "This is a case between two individuals and is a matter for the courts, not the government."
In 2008, Mr Anwar was accused of having sex with a male aide. A High Court cleared him of the charges in 2012, citing a lack of evidence.
The government later appealed against his acquittal.
The court decision comes ahead of a by-election Mr Ibrahim planned to contest
"It's truly a dark day for the Malaysia judiciary which has shown itself incapable of standing up straight when national political issues are in play in cases before them," Phil Robertson, deputy Asia head of group Human Rights Watch, said after the verdict.
Correspondents say Mr Anwar is seen as the key challenger to the ruling party, which has been in power since Malaysia's independence in 1957.
The Barisan Nasional coalition won 133 of the 222 seats in parliament in the 2013 elections - although it won the elections, it was the coalition's worst ever result.
Thousands of Malaysian opposition supporters rallied against the result, alleging that the polls were fraudulent.
Mr Anwar was previously a member of the Barisan Nasional coalition, but fell out with top leaders and was sacked in 1998.
He was then charged with sodomy and corruption, and given a six-year jail term for abuse of power, which sparked huge street protests.
In 2000 he was also found guilty of sodomy with his wife's driver and jailed for a further nine years.
In late 2004 Malaysia's Supreme Court overturned the sodomy conviction, freeing him from jail.
He then emerged as a leader in the opposition movement, leading it to increasingly strong performances in both the 2008 and 2013 elections.