Malaysia's Anwar Ibrahim was sworn in as prime minister on Thursday, ending a three-decade political career that saw him come close to winning the position twice.

His appointment puts an end to the unheard-of post-election situation that lasted five days, but his rival, former prime minister Muhyiddin Yassin, may challenge him to demonstrate his majority in parliament, which might spark new unrest.

In a Saturday election, neither man was able to secure a majority, but King Al-Sultan Abdullah, the country's constitutional monarch, appointed Anwar after consulting with many parliamentarians.

Anwar rose to prominence as a fiery student leader who created Malaysia's Islamic youth movement, ABIM. In 1982, he startled many by joining the long-ruling United Malays National Organisation (UMNO). But it proved to be a wise political decision, as he quickly ascended the political ladder and held numerous ministerial positions.

He became Mahathir Mohamad's deputy in 1993 and was generally expected to succeed him. However, tensions arose following the Asian financial crisis of 1997, when they disagreed over the economy and corruption.

After being fired in September 1998, Anwar organized public protests against Mahathir. It marked the beginning of the Reformasi reform movement, which had an impact on a generation of Malaysian democracy campaigners. Anwar was detained and ultimately accused of sodomy and corruption, which he vehemently denied in the contentious trial that followed.

While homosexual conduct is a crime in Malaysia, which has a majority of Muslims, convictions are uncommon and the prosecution against Anwar was widely criticized for being politically motivated.

After he was given a six-year prison sentence for corruption, there were violent public protests. He received a nine-year sodomy sentence a year later.

The accusations, according to Anwar, were part of a smear aimed at discrediting him as a political rival to Mahathir.

Anwar's sodomy conviction was reversed by Malaysia's Supreme Court in late 2004, a year after Mahathir stepped down as Prime Minister.

Anwar, now 75, has been denied the leadership multiple times despite being close: he was deputy prime minister in the 1990s and formal prime minister-in-waiting in 2018.

Now, Anwar takes over at a difficult time: the economy is stalling and the country is split following a close election that placed Anwar's progressive coalition against Muhyiddin's primarily conservative ethnic-Malay, Muslim alliance.

Anwar's followers hoped that his government would prevent a return to historic tensions between the ethnic Malay, Muslim majority, and ethnic Chinese and Indian minority.

"All we want is moderation for Malaysia and Anwar represents that," said a communications manager in Kuala Lumpur, who asked to be identified by her surname Tang. "We can't have a country that is divided by race and religion as that will set us back another 10 years."