Malaysia's king has agreed to pardon a politician whose case has gripped national politics for two decades, says new PM Mahathir Mohamad.

Special Correspondent

Anwar Ibrahim, once considered a potential future leader, was jailed on charges of corruption and sodomy after falling out with the government.

But Mr Mahathir, the PM under which he was first jailed, just won an election on a pledge of freeing him. Also He has indicated he will hand power to Anwar within a few years.

At a news conference on Friday, a day after his historic election win Mr Mahathir said the king "has indicated he is willing to pardon Datuk Seri Anwar immediately", using an honorific title.

"It is going to be a full pardon which of course means that he should not only be pardoned, he should be released immediately when he is pardoned. After that he will be free to participate fully in politics."

Mr Mahathir's election win, at the head of the Pakatan Harapan, (A collation of Opposition ) ended more than six decades of rule by the Barisan Nasional (BN) coalition.

Some have likened the twists and turns of Malaysian politics to a plot by Shakespeare novel.

Mahathir Mohamad, the autocratic strongman who turned on his chosen successor Anwar Ibrahim, is now allied with him and seeking his release, having deposed Najib Razak, another one-time Mahathir protege.

During the bitter election, Mr Najib called the alliance a "coalition of convenience" which, he warned, would fall apart if they won.

There are many strong personalities in the victorious coalition which will have to be reconciled, but none more important than Anwar and Mr Mahathir, who until his defection to the opposition, still described Anwar as morally unfit to lead the country.

Even with his remarkable fitness, he must, at 92 years old, consider his physical limitations. They're in coalition, but with only 13 seats in parliament Mr Mahathir's new party Bersatu is much smaller than Anwar's Keadilan, with 47. The days where Mr Mahathir could dictate his terms are probably over.

Both he and Anwar were formerly in power, as part of the BN, as prime minister and deputy respectively.

Special Correspondent

The story of their relationship is one of extraordinary twists and turns. Anwar was sacked in 1998 after a dispute with the coalition leadership and then led huge protests against Mr Mahathir's government. He was jailed a year later for abuse of power.

Then in 2000 he was convicted of sodomy, and given an additional nine-year-term.

Though sodomy is illegal in conservative Muslim Malaysia people are seldom convicted for it, so his case was widely seen as an attempt by the government to remove a political threat.

In 2004 his conviction was overturned and he led the opposition to unprecedented gains - though not victory - in the 2008 and 2013 general elections.

But that acquittal was itself overturned a year later - as he was preparing to fight a state election he seemed likely to win - and he was sent back to jail.

In a shock turn of events earlier this year, his former nemesis Mahathir Mohamad announced he was going to be running for the top office again.

He said he was sick of the corruption allegations plaguing the incumbent Najib Razak, another of Mr Mahathir's former allies.

Anwar has remained popular with opposition supporters, and a condition of Mr Mahathir being allowed to lead the coalition was that he agreed to secure a royal pardon.

He agreed, and further said he aimed to hand the prime minister post to Anwar within two years.

Will Mahathir keep his word to be seen because that will decide the course of this coalition opposition government in power.