KUALA LUMPUR: Malaysia's king appointed long-time opposition leader Anwar Ibrahim as prime minister on Thursday and he will be sworn in at 5 p.m. (0900 GMT), ending five days of unprecedented post-election crisis after inconclusive polls.

Anwar's appointment caps a three-decade long political journey from a protege of veteran leader Mahathir Mohamad to a prisoner convicted of sodomy to opposition leader and, finally, prime minister.

A general election on Saturday ended in an unprecedented hung parliament with neither of two main alliances, one led by Anwar and the other ex-premier Muhyiddin Yassin, immediately able to secure enough seats in parliament to form a government.

The 75-year-old Anwar has time and again been denied the premiership despite getting within striking distance over the years: he was deputy prime minister in the 1990s and the official prime minister-in-waiting in 2018.

In between, he spent nearly a decade in jail for sodomy and corruption in what he says were politically motivated charges aimed at ending his career.

The uncertainty over the election threatened to prolong political instability in the Southeast Asian country, which has had three prime ministers in as many years, and risks delaying policy decisions needed to foster economic recovery.

Anwar leads a multi-ethnic coalition of parties with progressive leanings while Muhyiddin's alliance reflects more conservative, ethnic Malay, Muslim views.

Anwar's coalition, known as Pakatan Harapan, won the most seats in Saturday's vote with 82, while Muhyiddin's Perikatan Nasional bloc won 73. They need 112 - a simple majority - to form a government.

The long-ruling Barisan bloc won only 30 seats - the worst electoral performance for a coalition that had dominated politics since independence in 1957.

Barisan said on Thursday it would not support a government led by Muhyiddin, though it did not make any reference to Anwar.

POLICE STEP UP SECURITY

Muhyiddin's bloc includes the Islamist party PAS, whose electoral gains raised concern in a country with significant ethnic Chinese and ethnic Indian minorities, most of whom follow other faiths.

Authorities warned after the weekend vote of a rise in ethnic tension on social media and short video platform TikTok said it was on high alert for content that violated its guidelines.

Social media users reported numerous TikTok posts since the election that mentioned a riot in the capital, Kuala Lumpur, on May 13, 1969, in which about 200 people were killed, days after opposition parties supported by ethnic Chinese voters made inroads in an election.

Police told social media users to refrain from "provocative" content and said they were setting up 24-hour check-points on roads throughout the country to ensure public peace and safety.

The decision on the prime minister came down to King Al-Sultan Abdullah Sultan Ahmad Shah, after both Anwar and Muhyiddin missed his Tuesday afternoon deadline to put together an alliance.

The constitutional monarch plays a largely ceremonial role but can appoint a premier he believes will command a majority in parliament.

Malaysia has a unique constitutional monarchy in which kings are chosen in turn from the royal families of nine states to reign for a five-year term.

As premier, Anwar will have to address soaring inflation and slowing growth, while calming the ethnic tensions.

The most immediate issue will be the budget for next year, which was tabled before the election was called but has yet to be passed.

Anwar will also have to negotiate agreements with lawmakers from other blocs to ensure he can retains majority support in parliament.