KUALA LUMPUR, Malaysia (AP) — More than two decades after his dramatic ouster from government and imprisonment, Malaysian opposition leader Anwar Ibrahim finally has his day.

Anwar was named Malaysia’s 10th prime minister by the nation’s king and sworn in Thursday, trumping a Malay nationalist leader to clinch the top job after divisive general elections led to a hung Parliament.

Becoming prime minister caps Anwar’s roller-coaster political journey, from a former deputy prime minister whose sacking and imprisonment in the 1990s led to massive street protests and a reform movement that rose into a major political force. It is a second victory for his reformist bloc, which won 2018 polls but lost power after 22 months due to a power struggle that has led to continuous political turmoil.

Last Saturday’s election, which was supposed to end the instability that had led to three prime ministers since 2018, instead produced new uncertainty after no party won a clear mandate. Anwar’s multiethnic Alliance of Hope, led with 82 seats, short of the 112 needed for a majority. Muhyiddin’s right-leaning National Alliance won 73 seats, with its ally Pan-Malaysian Islamic Party emerging as the biggest single party with 49 seats.

Anwar emerged victorious after smaller blocs agreed to back him to form a unity government. Still, he faces a tall task in bridging racial divides that deepened after Saturday’s poll and reviving an economy struggling with rising inflation and a currency that has fallen to its weakest point. Malays are two-thirds of Malaysia’s 33 million people, which include large ethnic Chinese and Indian minorities.

“Anwar’s political struggle is of a comparable level as (South Africa's) Nelson Mandela, as both went through many persecutions in the process of democratizing their countries," said Ei Sun Oh with Singapore's Institute of International Affairs. “It is hoped that with Anwar in charge, Malaysia could revert to a more open and inclusive society and economy that would hopefully restore its prestige on the world stage."

Anwar, 75, had been on the cusp of power twice.

A firebrand youth leader, Anwar founded an Islamic youth movement before he was recruited into the then-ruling United Malays National Organization. He enjoyed a meteoric rise to become deputy prime minister-cum-finance minister in the 1990s. He was groomed to take over from then-Prime Minister Mahathir Mohamad but a bitter fallout over Malaysia’s response to the Asian economic crisis saw Anwar sacked in September 1998, detained without trial and then charged with sodomy and corruption.

Tens of thousands took to the streets to protest Anwar’s treatment. When Anwar was brought to court with a black eye nine days after his arrest — due to an assault in custody by the country’s then police chief — it quickly became a symbol for his new People’s Justice Party and its vows for reforms. He was jailed six years for sodomy in 1999 and a year later, another nine years for corruption — charges Anwar said were a political conspiracy by Mahathir to end his career. His case drew international criticism, with Amnesty International calling Anwar a “prisoner of conscience.”

Anwar was freed in 2004 after Malaysia’s top court overturned his sodomy conviction, a year after Mahathir stepped down as prime minister after 22 years in power.

But Anwar was imprisoned a second time for sodomy in 2015 — in a case he said was aimed at crushing his alliance which was making gains against the UMNO-led government. Yet, he didn't give up.

From his prison cell, Anwar made up with Mahathir, who returned to politics as anger boiled over a multibillion-dollar scandal involving the 1MDB state investment fund. Their reunion led to historic 2018 polls that saw the unthinkable ouster of the UMNO-led alliance, which had led since Malaysia’s independence from Britain in 1957.

Mahathir became the world’s oldest leader at 92 after the victory. Anwar was pardoned shortly after and would have succeeded Mahathir, but infighting led to their government’s collapse just after 22 months. UMNO returned as part of a quarrelsome government with Muhyiddin’s National Alliance bloc that includes a hardline Islamic ally.

Still, the brief rule by Anwar’s Pakatan Harapan led to a significant upheaval as once-power UMNO leaders were jailed or brought to court for graft. Former Prime Minister Najib Razak was imprisoned in a case linked to the 1MDB saga. His wife, UMNO’s current chief and several party leaders are also battling separate corruption charges.

Anwar campaigned on a multiracial platform, promising to end racial and religious bigotry and plug billions of dollar lost to entrenched corruption. He finally succeeded in his dogged quest Thursday after a long battle.

Copyright 2022 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed without permission.