The 92-year-old comeback kid of Malaysian politics, Mahathir Mohamad, had been in power for less than 24 hours when he made an announcement that effectively heralded his own downfall.

On Friday, Mr Mahathir said he had successfully secured a royal pardon for the opposition icon Anwar Ibrahim, a man who had joined him in coalition from the confines of a prison cell.

It marked the latest extraordinary twist in a heady few days for politics in the southeast Asian nation. Mr Mahathir, the former authoritarian leader who stepped down after 22 years in power in 2003, has vowed to hand over the reins once again if Mr Anwar is released from jail.

Mr Anwar, a former protegee of Mr Mahathir until the pair fell out in 1998, retains huge popularity among a generation of Malaysians who see him as the wrongly imprisoned reform candidate of the turn of the millennium.

The victorious opposition coalition, Pakatan Harapan, which collectively won 122 seats of the 222-member parliament in this week’s general election, only backed Mr Mahathir as leader on the condition that he eventually make way for Mr Anwar, and that he take Mr Anwar’s wife, Wan Azizah Wan Ismail, as his deputy. She is now the first female deputy premier in Malaysia’s history.

Analysts say Mr Anwar’s cross-ethnic support was critical to Pakatan Harapan’s success, and it is now a matter of when, not if, Mr Mahathir steps aside.

After meeting with Sultan Muhammad V, Malaysia’s constitutional monarch, Mr Mahathir said the king had indicated he is willing to give an immediate pardon that would free Mr Anwar from his second spell in prison, on 2015 sodomy charges which many believe were politically motivated by the then-government of ousted prime minister Najib Razak.

Ms Wan Azizah went to visit her husband in hospital on Friday, and afterwards told reporters he could be out of custody in days and have his pardon within a week. He is currently warded at a hospital in Cheras to recover from recent surgery.

She said: “The agong (king) wants the pardon to happen as soon as possible. If the director of prisons is satisfied … then he may be released in two to three days. Freedom is easier [than getting a pardon].”

Once out of prison, Mr Anwar will need to wait for a byelection to become a member of parliament before he can be named as the new prime minister – a process which, combined with the pardoning, Mr Mahathir has previously suggested could take up to two years.

Bridget Welsh, a leading expert on Malaysian politics and associate professor at John Cabot University in Italy, told The Independent that it may actually help Mr Anwar to let Mr Mahathir lead for the time being.

“Anwar’s supporters are ambitious and would like an early turnover,” she said. “But it is in Anwar’s interest to allow Mahathir to make the reforms needed to the system, politically and economically, given the mandate he has received.”

A major corruption scandal involving money allegedly siphoned from a Kuala Lumpur development programme, plus an unpopular new sales tax, are seen as being responsible for the incumbent Mr Najib’s defeat in the election.

Mr Mahathir, himself not immune to allegations of corruption in the past, made much in his campaign of cleaning up the government, and on Friday said many suspected corrupt civil servants could expect to lose their jobs in the coming weeks.

The idea would be that once Mr Mahathir has fulfilled his election mandate, Mr Anwar would be in a freer position to carry the country forwards.

“We will see how they work together, and whether they remain focused on the nation as opposed to themselves and their supporters,” Ms Welsh added.

Mr Mahathir’s age may also play a factor in the duration of his latest tenure as prime minister. Though remarkably well for a 92-year-old, he will inevitably face questions around his health and ability to lead.

Malaysian opposition leader Anwar Ibrahim smiles as he leave the Palace of Justice in Putrajaya, Malaysia, 3 November 2014 (EPA)

For now, though, he is the fresh face welcomed by Malaysians disillusioned by the increasingly unpopular administration of Mr Najib.

People were “simply fed up” with the party that had run Malaysia for 61 years, said Joseph Liow Chin Yong, professor of international politics at the S Rajaratnam School of International Studies in Singapore.

“But of course, the presence of both Mahathir and Anwar played a role to catalyse things,” he added. “The fact that Mahathir and Anwar reconciled, or so it seems, really fired up the imagination of what Malaysia can achieve in a post-Najib, post-UMNO (former ruling party) era.”

Mr Mahathir said his four-party alliance will hold a meeting on Saturday and name just 10 ministers, adding that he does not want a “huge” cabinet – an apparent reference to the bloated cabinets of more than 30 ministers in the past.

And he indicated one of his first acts as prime minister would be to replace the attorney general, Mohamed Apandi Ali, who was appointed after Mr Najib sacked his predecessor in 2015 to escape possible prosecution over what is known as the 1MDB corruption scandal.

1MDB was a state fund set up by Mr Najib in 2009 to promote economic development in the capital, but it accumulated billions in debts. US investigators say Mr Najib’s associates stole and looted at least $4.5bn (£3.3bn from the fund.