It was a stunning triumph that almost no one had predicted and ended the long hold on power of the Barisan Nasional (BN) coalition, which has ruled Malaysia since its birth as an independent country.
The victory capped a dramatic political comeback for Mahathir, who previously ruled the country with an iron fist for 22 years, and came out of retirement to taken on Prime Minister Najib Razak after the leader became embroiled in a massive corruption scandal.
When he takes power, Mahathir Mohamad, 92, will be the oldest prime minister in the world.
His victory spells big trouble for Najib – Mahathir has vowed to bring him to justice over allegations that billions of dollars were looted from sovereign wealth fund 1MDB, which the scandal-plagued leader set up and oversaw.
But at a press conference, Mahathir vowed: “We are not seeking revenge. We want to restore the rule of law.”
Mahathir’s return to the political frontlines saw him throw in his lot with an opposition alliance filled with parties that he crushed while in power, and which includes jailed opposition icon Anwar Ibrahim – his former nemesis.
As well as seizing control of the national government, several state legislatures across the country fell into opposition hands for the first time, including the highly symbolic bastion of Johor, the birthplace of Najib’s party that was the lynchpin of the ruling coalition.
Official results from the Election Commission showed that Mahathir’s opposition grouping Pakatan Harapan, along with an ally in the Borneo state of Sabah, had secured 115 parliamentary seats. 112 are needed to form a government. BN were on 79 seats with just a few left to count.
As it became clear that Mahathir had won, supporters took to the streets waving flags of the opposition alliance.
After polls closed earlier in the day, journalists had flocked to the headquarters of Najib’s United Malays National Organisation (UMNO), the lynchpin in the ruling coalition – but he failed to turn up to give a victory speech and the media were told to leave.
Huge numbers of voters earlier flocked to the polls across the country, despite Najib having called the election on a weekday in what critics said was a bid to keep turnout down.
The BN wipeout is a disaster for Najib, who had been under pressure to score an emphatic win after the government lost the popular vote for the first time at the last elections in 2013.
The controversy surrounding 1MDB has dogged Najib since the story exploded in 2015. Billions of dollars were allegedly stolen from the fund, which was set up and overseen by Najib. The leader and 1MDB deny any wrongdoing.
But in rural areas, the rising cost of living, which has hit poor Malays hard, was the main concern at the election particularly after the introduction of an unpopular sales tax in 2015.