Kuala Lumpur (Web Desk): At the age of 92, Mr Mahathir has defeated the Barisan Nasional coalition, which has been in power 60 years, BBC reported.
According to details, he had come out of retirement to take on his former protege Najib Razak, who has been beset by allegations of corruption and cronyism.
Mr Mahathir told BBC: "We are not seeking revenge, we want to restore the rule of law".
The election commission said Mr Mahathir 's opposition alliance had won 115 seats, over the threshold of 112 seats needed to form a government.
He said he hoped a swearing-in ceremony would be held on Thursday. Mr Mahathir will become the oldest elected leader in the world.
The former PM, 92, came out of retirement and switched to the opposition to challenge his former protege Najib Razak, who has been beset by corruption allegations.
His historic win has ousted the Barisan Nasional (BN) coalition, which has been in power since independence in 1957.
Mr Mahathir said his coalition would "restore the rule of law".
Mr Najib has not yet commented on his dramatic loss.
Official results showed the opposition Pakatan Harapan - the Alliance of Hope - had secured 113 of the 222 being contested, including some which have never before been taken by the opposition. BN took 79 seats.
Announcing his victory in Kuala Lumpur, Mr Mahathir said his coalition had secured "not just a few votes, not just a few seats, but a very substantial majority".
He said he hoped a swearing-in ceremony would be held on Thursday and announced - to cheers among his supporters - that there would be a two-day holiday.
"But there will be no holidays for the winners."
Opposition supporters - most of whom have only ever lived under one government - poured on to the streets overnight in celebration.
"I feel that with this change we probably can see something better in the future," Suva Selvan, a 48-year-old doctor, told media.
"Our hope for the future is a better government, fair, free and united."