Anwar Ebrahim Image Credit: Reuters

Kuala Lumpur:  Jailed Malaysian politician Anwar Ebrahim walked free on Wednesday after receiving a royal pardon, paving the way for his return to national politics as the presumptive successor to Prime Minister Mahathir Mohammad following a stunning election upset.

Anwar declared 'new dawn for Malaysia' following his release.

Smiling and looking spry in a tailored black suit, Anwar emerged from a Kuala Lumpur hospital where he had undergone surgery for a shoulder problem, giving a thumbs-up to a crowd of journalists before leaving in a convoy of cars without making any public comment.

Officials in Anwar's political party said he was headed to an audience with Malaysia's king and was expected to address the public in the afternoon followed by a political rally in the evening.

Anwar, now 70, was granted a royal pardon over a sodomy conviction that saw him jailed for the past three years.

Hie release caps a remarkable reversal of fortune made possible by the unexpected electoral defeat last week of the corruption-plagued ruling coalition that held power for the last six decades.

Anwar cannot directly join the government anytime soon.

He must first be elected to parliament, having been stripped of his seat in 2015 when his conviction on charges of sodomising a young male aide was upheld on appeal, sending him to jail.

That conviction is viewed by many in Malaysia as politically motivated, orchestrated by the previous government in a bid to decapitate Anwar's rising opposition movement.

His release is likely to add to public feelings of excitement about a new era in the country following the stunning election result.

It sets up a tantalising reunion with his one-time mentor turned nemesis and now ally again - Mahathir Mohamad.

The 92-year-old former autocrat Mahathir had headed the now-ousted Barisan Nasional regime for 22 years until 2003 but came out of retirement to lead a disparate opposition to an unexpected election victory.

Mahathir has said he expects to run the government for up to two years but has signalled the reins would be turned over to the Anwar eventually.