KUALA LUMPUR, Malaysia—Former leader Mahathir Mohamad was set to return to the premiership after pulling off an astonishing election upset to defeat the ruling coalition of his former protégé, Prime Minister Najib Razak, who had faced allegations he stole hundreds of millions of dollars from state investment fund 1MDB.

Official results early Thursday confirmed that the 92-year-old Dr. Mahathir’s Alliance of Hope coalition had secured a majority by taking 122 seats in the 222-member Parliament. Opposition supporters celebrated...