In May 2018, Dr Mahathir Mohamad was in the grand ballroom of a Sheraton hotel near Kuala Lumpur, jubilantly announcing his return as prime minister after defeating an alliance that had run the country for 60 years.

Less than two years later, the coalition assembled by the 94-year-old crumbled in the same hotel, as members of his party held meetings with their former opponents that eventually led to his downfall.

Mahathir has shaped Malaysia like no other politician since the Southeast Asian nation became independent, with a 22-year stint as prime minister that started in 1981 and then a second term after his historic return two years ago.

It's not clear, given his age, if he can pull off another comeback.

The political machinations that led to Mahathir's resignation were started several months ago with his knowledge, the aim being to block his former deputy and rival-turned-ally Anwar Ibrahim from taking power, more than a dozen sources told Reuters.

The timing went awry, said the sources, who had direct knowledge of the events but declined to be identified because of the sensitivity of the subject.

In the ensuing turmoil, Mahathir was outplayed by colleagues and close allies, including Muhyiddin Yassin, who took the premiership, the sources said. He was also rebuffed by the country’s powerful sultans, from whom the king is chosen by rotation.

Spokesmen for Mahathir, Anwar and Muhyiddin did not respond to requests for comment on this story.

Anwar was deputy prime minister under Mahathir in the 1990s and was seen as his successor-in-waiting in a government led by Umno.

In 1998, they disagreed on how to tackle the Asian financial crisis and fell out. Anwar was sacked, and he launched a 'Reformasi' (reform) movement to end Umno’s race-based governance that favoured the country's Malay majority.

In an astonishing U-turn two years ago, the two came together to form the reformist Pakatan Harapan to oust Najib Razak's Umno government.

Under a pre-election agreement, Anwar was to take over as prime minister from Mahathir. It was not specified when.

However, in recent months, Mahathir was not convinced his former deputy would be able to command a majority, sources said. He was also facing pressure from aides who said the alliance's fortunes were slipping because of Malay anger against the presence of the Chinese-dominated DAP in its fold.

‘Stop Anwar’

Initially, "the main goal of everyone was to stop Anwar," said one source close to Muhyiddin. That would help dismantle the multiethnic Harapan alliance and fashion a government more aligned with the Muslim Malays.

Muhyiddin and Mohamed Azmin Ali, then a member of Anwar's party, reached out last year to Umno and Islamist party PAS, both in the opposition, to explore chances for a realignment, sources close to Mahathir and Muhyiddin said. Mahathir was aware of the talks and did not object, they said.

Mahathir however refused to work with all Umno leaders, especially former prime minister Najib, who is on trial for corruption.

Azmin did not respond to requests for comment.

Najib told Reuters on Wednesday discussions for a new coalition had been going on for months.

The original plan had been to make a move after the Asia Pacific Economic Cooperation (Apec) summit in Malaysia in November - and put the question of Anwar's premiership to parliament in the expectation it would be voted down, sources said.

But things came to a head-on Feb 21 when Anwar's supporters challenged Mahathir at a meeting to set a date to hand over. One source with knowledge of the matter described the tone of the demand as "uncouth", leaving Mahathir furious.

In response, Mahathir's allies moved up their plan and summoned their potential new partners to a dinner at the Sheraton hotel on Feb 23. In the so-called "Sheraton Move", members of Mahathir's Bersatu party and Umno joined in a very public show of the changes afoot.

Umno leaders told reporters the Harapan coalition had fallen and they backed Mahathir for prime minister. Anwar said in a Facebook broadcast that he was betrayed.

But Mahathir had not been at the Sheraton and was adamantly against the plan since it involved all of Umno, including Najib.

What nobody expected was that he would simply resign as prime minister the next day, Feb 24.

In tears, Mahathir told Anwar and other Pakatan coalition partners that he no longer had his own party's support and was not behind the moves to partner with Umno, sources familiar with the discussions said.

From the shadows

In a counter-move, Mahathir offered to lead a unity government with whoever would join. He wanted no party affiliations, a move his detractors thought would give unilateral control.

The reactions were swift. Umno and PAS called for early elections. Anwar said he was now the Pakatan coalition's candidate for prime minister.

When it became clear that Mahathir's national unity plan was not gaining support, a new candidate for prime minister emerged from his Bersatu party: Muhyiddin.

"He says politics is more important than principles," Mahathir said of Muhyiddin later, referring to his willingness to partner with all of Umno.

Muhyiddin had long been overshadowed by his contemporaries Anwar and Najib. He had been fired by Najib as deputy premier in 2015 for criticising alleged corruption.

Amid the turmoil, King Sultan Abdullah Sultan Ahmad Shah began consultations with all 222 lawmakers to find a candidate for prime minister.

By now, momentum was building behind Muhyiddin and people close to Mahathir began switching sides.

The main message from Muhyiddin, sources close to him said, was the importance of building an alliance that did not include Anwar and the Chinese-dominated DAP, long the bogeyman for Malays.

Mahathir went back to his old alliance with Anwar that agreed to support him for premier but it was too late.

Later that day, the king, after consulting with the council of sultans, announced Muhyiddin was the man likely to be able to command a majority in parliament.

Mahathir cried foul and complained that he could show that he had majority support. The palace said nothing.

In a sign of where some royal sentiment lay, the crown prince of the powerful sultanate of Johor posted a picture of himself on Instagram, saying "Who's your daddy now?" Mahathir had taunted the prince last year as "a little boy."

Mahathir kept trying to contact the king, who would not take his calls, one source close to Mahathir said.

Less than an hour before Muhyiddin was sworn in, Mahathir conceded that he would have to leave the prime minister's office, at least for now.

"The king has made a decision not to see me anymore," he said. "I cannot communicate with the palace."

- Reuters