Former Malaysian leader Dr Mahathir Mohamad is poised to become the world’s oldest prime minister after defeating Najib Razak in a fiercely contested election that put an end to the ruling coalition’s six-decade hold on power.

Mahathir, 92, who was prime minister between 1981 and 2003, led the opposition coalition, Pakatan Harapan, to its first election victory since Malaysian independence in 1957, winning an outright parliamentary majority. He will be sworn in by the king on Thursday.

A euphoric mood gripped Malaysia at the announcement, which many had believed impossible. “We are so happy, such a proud day for Malaysia,” said David Thaiga, 57, who joined others in the street to celebrate.

“We have been waiting for this for the past 60 years. This is a miracle for us. And even though I was not a fan of Mahathir, I think he was the only one who could have brought this victory.”

Malaysia election 2018: everything you need to know Read more

Sukumira Sekhar, 84, witnessed the beginning of Malaysian independence and lived through 60 years of rule by the Barisan Nasional (BN) coalition, said: “I’m so happy I survived to see this. I wish I could jump up and down for joy, but be sure my heart is jumping up and down. I’m so proud of the people of Malaysia, especially the young people and the Malays who swung it.”

Mahathir’s win marks the end of the nine-year tenure of Najib, who came to power in 2009 and whose reputation was tarnished by the 1MDB corruption scandal in which $2.6bn was embezzled from a government fund he was overseeing – including $681m that was alleged to have ended up in his personal bank account.

Quick guide 1MDB Show Hide The scandal 1Malaysia Development Berhad, was set up in 2009 to promote economic development. The Malaysian prime minister, Najib Razak, chaired its advisory board and, according to the US Justice Department, top executives and associates of Najib looted $4.5bn from the fund between 2009 and 2014, laundering it through the US, Singapore, Switzerland and other countries. Hundreds of millions landed in Najib's bank account, though he denies any wrongdoing. Where the money went The US Justice Department is seeking to recover money from the fund it says was gambled in Las Vegas, used to buy hotels, apartments, a luxury yacht, a jet, diamond jewellery, art works and to finance Hollywood films including the Wolf of Wall Street and Dumb and Dumber To. The investigation US prosecutors have alleged layers of foreign bank accounts and shell companies were used to launder the money and named Low Taek Jho, a friend of Najib’s stepson, as a key figure in the conspiracy. In one email he wrote "Looks like we may have hit a goldmine" after organising a 1MDB deal that would later allegedly become a money laundering vehicle. Singapore has fined eight banks for failing to carry out proper anti-money laundering measures in relation to 1MDB and given prison sentences to several bankers. Political impact A parliamentary inquiry found many irregularities but had no mandate to prosecute so, outraged by the scandal, 92-year-old former leader Mahathir Mohammad came out of political retirement and opposition united behind him for the elections. The government recently passed a "fake news" law that could be used to further stifle reporting on the case within Malaysia.

Mahathir’s victory marks the first time that a Malaysian prime minister will not be from the UMNO party and not be part of the BN coalition, of which UMNO is the main constituent.

The win indicates that a mood for change has gripped the country, following the “Malay tsunami” in which many ethnic Malay voted for the opposition for the first time.

Voter turnout was 76% – lower than in the 2013 election – but the opposition took many states that were considered BN strongholds such as Johor, Malacca and Negeri Sembilan.

The campaign also galvanised the youth vote for the first time, with young people taking to social media to add their support to the opposition.

“This is a pure adrenaline rush. We have been waiting for this change for the longest time,” said Naveen Kumar, 31. “We have been infected with a BN government for so long and now it’s a total relief.”

Profile Mahathir Mohamad Show Hide Dr Mahathir Mohamad was Malaysia's longest-serving prime minister, holding office from 1981 to 2003. He is credited with overseeing a period of economic growth but was also notoriously authoritarian, cracking down on the opposition, the judiciary and the press. Mahathir selected Abdullah Badawi as his successor, but toppled him in 2009 after a poor election performance and installed another protege, Najib Razak, as prime minister. Having officially retired, Mahathir then denounced Najib in 2015, after the 1MDB scandal broke. In 2018, it was announced he had switched to the opposition party, and, at 92 years old, would be running again as prime minister to bring down Najib. If his win is confirmed, he will be the oldest leader in the world. Photograph: Lai Seng Sin/X03855

Shaliz Kumar, 28, said: “The young people had a big part to play in this. I called all my friends to make sure they had voted.”

The official results, usually announced by 11pm, were not released until around 3am, and some alleged that Najib was trying to stall the announcement. Constituencies that were swinging towards the opposition also reported electricity blackouts, hindering the final count.

In the end, however, Najib made no public statement after Mahathir had claimed victory in the early hours of Thursday morning.

'This election is personal': Mahathir Mohamad, 92, vows to stop 'corrupt' protege Read more

Mahathir’s selection as opposition leader had made this an unusual election: he was an UMNO member when he first came to power in 1981, and played a key role selecting his protege Najib as prime minister in 2009.

The relationship soured in 2015 after Najib was implicated in the 1MDB scandal, and this year Mahathir announced he was not only forming his own political party, Bersatu, but switching sides and joining the opposition coalition.

Najib had initially been expected to win easily, but, as campaigning picked up, the opposition dominated the narrative, raising issues such as corruption and the rising cost of living.

After claiming victory on Thursday morning, Mahathir was asked whether he would seek to prosecute Najib for his alleged role in the 1MDB scandal. “We are not seeking revenge, we are seeking to restore the rule of law,” he said.

1MDB: The inside story of the world’s biggest financial scandal | Randeep Ramesh Read more

As part of his agreement with Pakatan Harapan, Mahathir will only be prime minister for two years, and then will cede power to Anwar Ibrahim. Anwar, who was also once Mahathir’s protege, is currently in jail serving a second sentence for sodomy.

Mahathir and Anwar fell out publicly in 1999 and Mahathir was responsible for jailing Anwar, but the pair put aside their differences in their united desire to take down Najib.

The plan now is for Mahathir to have Anwar pardoned so he can take office. “He’ll be released in June,” said Mahathir. “Once he’s pardoned, he’s eligible to be PM again.” Mahathir also announced after his victory that he would appoint Wan Azizah, Anwar’s wife, as his deputy prime minister.

The police have warned people against gathering in the streets to celebrate in case of rioting; however, a large group gathered outside the Pakatan Harapan headquarters in Petaling Jaya to cheer and wave flags.

For Dr Mohan Mahatheva, who was in the crowd, “tonight this is true freedom for Malaysia. We freed ourselves from colonialism, now we have freed ourselves from kleptocracy,” he said. “At least I know my children will live in a truly independent Malaysia.”

• This article was amended on 10 May 2018. Because of an editing error, an earlier version said incorrectly that Selangor and Penang were considered BN strongholds.