A first time change
Malaysia has been ruled by the same coalition of parties - the Barisan Nasional - since it stopped being a British colony in 1957.
Although its popularity had been declining, most people believed Prime Minister Najib Razak was going to lead it to yet another win.
But the official count showed it didn't win enough seats in parliament to claim victory, a shock to most observers.
Why did they get voted out?
As ever, it's mostly the economy. The cost of living has gone up a lot and the government brought in a new tax on goods and services - never a popular move.
Najib Razak has always denied that he was involved in any corruption
But the biggest story out of Malaysia in recent years has been corruption. Najib Razak had set up a special fund to encourage foreign investment. But people involved in it have been accused of using it for their personal gain.
Najib was even accused of pocketing $700m. Importantly, he has always denied this and has been cleared of wrongdoing at home, but he and the fund are still being investigated by several countries, including the US, so it's been damaging for Malaysia's reputation.
That's where Mahathir Mohamad comes in
He's been prime minister before, as leader of the BN. For 22 years in fact, from 1981 until he stood down in 2003. He was also something of a mentor to Mr Najib.
This woman shows her inked finger, a way of making sure people don't vote twice
But two years ago he shocked everyone by saying he was so "embarrassed" by the corruption allegations that he was leaving his old party and would join the opposition, the Pakatan Harapan (Alliance of Hope).
Then in January, he said he would directly challenge his former mentee in the election, saying he felt confident of victory "unless Najib cheats".
And there were a lot of cheating allegations during the election: people said they didn't get their postal ballot, and the government rejigged some constituencies in a way critics said would help it win.
The government also jumped on the global "fake news" panic and rushed through a law which meant you could be jailed for sharing it.
Some people thought that was a way of shutting down criticism of the government. Mr Mahathir has even been charged under the law.
What happens now?
On Thursday, Mr Najib said he accepted "the verdict of the people". But he also said the next prime minister would have to be someone who wins the trust of MPs.
Mr Mahathir will almost certainly be that prime minister, but he has promised to hand over power in two years because - reminder - he is 92.
Opposition supporters are ecstatic.
That might deliver another stunning twist, because that next prime minister could well be Anwar Ibrahim - another former ally of Mr Mahathir's who he kicked out of office.
Anwar Ibrahim is currently in jail for allegedly having sex with a male employee.