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.
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 Sri Anwar immediately", using a formal term of address.
"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, ended more than six decades of rule by the Barisan Nasional (BN) coalition.
Both he and Anwar were formerly in power, as part of the BN, as prime minister and deputy respectively. 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.
It remains unclear when the pardon will be issued, and Mr Mahathir warned his supporters that the process of Anwar becoming an MP again so he can take on the leadership "might take a long time".
More about: Malaysia