Mahathir Mohamad is on course to become the world’s oldest elected leader at 92, after a shock victory in Malaysia’s bitterly fought election.
The former PM came out of retirement and defected to the opposition to take on his one-time protégé Najib Razak, beset by corruption allegations.
His historic win has ousted the Barisan Nasional (BN) coalition, which has been in power since independence in 1957.
Jubilant Mahathir supporters filled the streets as the victory became clear.
Mr Najib has said he will “accept the verdict of the people”, but correspondents say a smooth transition to power is not a given after such a major political upheaval.
No single party within the coalition won a majority, so technically it now rests with Malaysia’s king to decide who forms a government.
How have people reacted?
“Yes, yes, I am still alive,” Mr Mahathir told a news conference in the early hours of Thursday. He said his coalition would not seek revenge but would “restore the rule of law”.
He also announced – to cheers among his supporters – that there would be a two-day public holiday, adding: “But there will be no holidays for the winners.”
The official results showed the opposition Pakatan Harapan – the Alliance of Hope – secured 113 of the 222 seats being contested, including some which have only ever been held by the government. BN took 79 seats.
Rising living costs and long-running allegations of corruption weighed heavily on many voters and saw them peel away from Mr Najib and his once unshakeable coalition.
“I feel that with this change we probably can see something better in the future,” Suva Selvan, a 48-year-old doctor, told AFP.
“Our hope for the future is a better government, fair, free and united.”
How did Mahathir manage to win?
Mr Mahathir was prime minister, at the head of the BN coalition, for 22 years, from 1981 until he stepped down in 2003.
Under his leadership, Malaysia became one of the Asian tigers – the group of countries which saw their economies expand rapidly in the 1990s. But he was an authoritarian figure who used controversial security laws to lock up his political opponents.
Most infamously his deputy prime minister, Anwar Ibrahim, was sacked and accused of corruption and sodomy – and later jailed on the latter charge – when he called for economic and political reforms.
Mr Mahathir was also a mentor to Mr Najib, who became prime minister in 2008.
But Mr Najib has been dogged by corruption allegations. He has been accused of pocketing some $700m from the 1Malaysian Development Berhad, a state investment fund he set up.
He has vehemently denied all allegations and been cleared by Malaysian authorities but the fund is still being investigated by several countries. Mr Najib has been accused of stifling Malaysian investigations by removing key officials from their post.
Those allegations led to Mr Mahathir’s surprise defection in 2016 from Barisan Nasional to join the Pakatan Harapan, saying he was “embarrassed” to be associated “with a party that is seen as supporting corruption”.
Then in January, he said he would run for the leadership again.
But despite his historic win, uncertainty hangs over his tenure. Prior to his win, he intended to govern for two years before stepping down. He promised he would arrange a pardon for Anwar, clearing the way for him to be re-elected and take the top job.
‘Mountain of challenges’
Analysis: Jonathan Head, BBC South East Asia correspondent
This morning Malaysia has woken to an entirely new situation, the first transfer of power in its history, albeit to a very familiar leader. But there are huge unknowns. How willingly will Barisan Nasional, the coalition which has, in various forms, run the country since independence and embedded itself into all areas of governance, relinquish power?
How well will a disparate coalition, united largely by their desire to oust Najb Razak, work together in government? How smoothly will the plan to gain a pardon for imprisoned opposition leader Anwar Ibrahim, and then for Mr Mahathir to hand the premiership to him within two years, actually proceed? And how will they treat Mr Najib, and his high-spending wife, both accused of greed and corruption?
After all the jubilation over an impressive act of defiance by Malaysian voters, there is a mountain of challenges to face.
What controversies surrounded the vote?
Ahead of the election, there were allegations that voting would not be free and fair.
The government recently passed a law redrawing election boundaries, leading to accusations that it had gerrymandered constituencies to ensure they were filled by Malay Muslims, traditionally BN supporters.
A controversial fake news law was also recently introduced, which critics say could be used by the authorities to muffle dissent. Mr Mahathir is himself being investigated under that law after alleging that his plane had been sabotaged.
And in the days before the poll, election reform group Bersih 2.0 accused the Election Commission (EC) of multiple “electoral crimes”, including irregularities in postal voting and failing to remove dead people from the electoral roll.
The government had insisted the election would be free and fair, with Mr Najib saying that the EC acted “for the good of all”.