Anwar has been a deputy prime minister, a protest leader and an opposition leader.

And spent a decade in prison on sodomy charges he said were cooked up to thwart his career.

Anwar's supporters gathered outside his house in Kuala Lumpur, praying and hugging one another.

His appointment ends five days of unprecedented post-election deadlock and markets surged on the news.

But it could usher in new instability.

Anwar's rival, former prime minister Muhyiddin Yassin, has challenged him to prove his majority in parliament.

Both men failed to win a majority in Saturday's (November 19) election, which was close and pitted Anwar's progressive coalition against Muhyiddin's mostly conservative ethnic-Malay, Muslim alliance.

King Al-Sultan Abdullah appointed Anwar after speaking to several lawmakers.

Local resident Varshadoshi hoped the country could now move on.

"I think the focus now should be the people of this country, not politicians with their egos, but work towards reviving this country. That's all I'm asking for."

Anwar takes on a slowing economy and a divided country. Malaysia has had three prime ministers in as many years.

His supporters hope his government will prevent a return to historic tension between the ethnic Malay, Muslim majority and ethnic Chinese and Indian minorities.

Seventy-five-year-old Anwar has time and again been denied the premiership.

He started out as a protege of veteran leader Mahathir Mohamad. He was deputy prime minister in the 1990s and, in 2018, the official prime minister-in-waiting.