Second acts in politics are not unknown. But the rise, fall and rise again of Mahathir Mohamad, the father of modern Malaysia, is a rare story where a historic figure gets a chance to right the wrongs that he was responsible for. Dr Mahathir is Malaysia’s new prime minister and – at 92 – the world’s oldest leader. He won by defeating the party he led for over two decades, ending the career of his former protege Najib Razak. This is an electoral earthquake: the United Malays National Organisation (UMNO) has run Malaysia since its independence 61 years ago. The opposition that Dr Mahathir now leads was originally formed to oppose his own autocratic rule. Yet Dr Mahathir will take power, he says, only to give it away: handing over to a former apprentice who he saw jailed on trumped-up charges after the pair fell out and remains behind bars, as well as reversing draconian laws designed to shackle journalists who had exposed corruption.

This election is a game changer in south-east Asia, where democracy’s charms have been resisted. The peaceful transfer of power is a victory for justice and restores faith in voters to do the right thing. It is also a just punishment for Mr Najib, who was identified as “Malaysian Official 1” by the US Department of Justice and accused of pocketing $681m looted from a state development fund, 1MDB. He denied any wrongdoing, saying the money was a gift, later returned, from an unnamed Saudi royal. Mr Najib thought he could win by pitting Malaysia’s ethnic groups against each other, jailing critics, further gerrymandering the electoral map in his favour and even promising young voters zero income tax. It all failed, thanks to Malaysians being fed up with rising inflation, paranoia and absurd levels of graft. They wisely delivered the country’s first ever change of government.

This has been a long time coming. At the last election, in 2013, the ruling coalition failed to win the popular vote but retained power because of a grossly unfair electoral system. The leader of the opposition, Anwar Ibrahim, was then jailed on flimsy evidence for sodomy, which is a crime in Malaysia. Mr Anwar was last jailed after falling out with Dr Mahathir – using similar sham charges. Mr Anwar is in fact Malaysia’s most famous political prisoner – and his only offence is being charismatic and intelligent. Years out of office have finally mellowed Dr Mahathir and given him an empathy that in office he almost never revealed. This, coupled with Malaysia’s fall into the grip of political gangsterism, forced Dr Mahathir to join forces with his former rival Mr Anwar. It was in an interview with the Guardian last year that he acknowledged that he should have allowed Mr Anwar to succeed him, expressed regret that he did not and said Mr Anwar ought to be released from jail. This declaration, according to the influential Sarawak Report, reset politics in Malaysia.

The next test for the Pakatan Harapan governing coalition will be when Mr Anwar is released in June. He is almost certain to return to parliament and Dr Mahathir will have to make good on his promise to give up the throne. The coalition will have to launch an investigation into the disappearance of $4.5bn from 1MDB – and do so without it appearing a witch-hunt. Managing Malaysia’s delicate racial politics requires understanding and a light touch, though this may be easier as the ruling coalition is grounded in both Malay and Chinese communities. But these are welcome challenges for a Muslim-majority nation where the public should be congratulated for proving that voting does make a very real and refreshing difference.