Malaysian opposition leader Anwar Ibrahim's acquittal on sodomy charges has been overturned.

A Court of Appeals panel sided with a government challenge to Mr Anwar's 2012 acquittal on charges he sodomised a male former aide, saying a lower court had misjudged evidence.

Mr Anwar, 66, was sentenced to five years in jail, but freed pending appeal.

Once a rising star in Malaysia's long-ruling party until his spectacular ouster in the late 1990s, Mr Anwar has alleged a long-running campaign by the ruling regime to destroy his political career with false charges.

He bitterly rebuked the judges after the ruling.

"It is a travesty of justice. I would have thought you would have some courage," he said to the panel.

The ruling sparked an uproar in a courtroom filled with Mr Anwar's opposition colleagues and supporters, as his wife and three daughters burst into tears.

About 150 Anwar supporters demonstrated outside the appeals court in the administrative capital of Putrajaya after the announcement, chanting the opposition's battle cry of "Reformasi" (Reform), as a heavy police presence ringed the building.

Sodomy is illegal in Muslim-majority Malaysia and punishable by up to 20 years in jail.

Mr Anwar plans to appeal to the Federal Court, Malaysia's highest.

If that fails, besides being jailed, he would also be stripped of his parliament seat, disqualifying him from leading the opposition.

Mr Anwar denounced Prime Minister Najib Razak and the "arrogant" United Malays National Organisation (UMNO), the authoritarian ruling party that has governed tightly since independence from Britain in 1957.

"They want to end Anwar's political career but they underestimated the wrath of the people and I believe in the wisdom of the people," he said.