They were the oddest of political colleagues: a nonagenarian onetime autocrat and the former protégé he had jailed for sodomy.
Mahathir Mohamad, the 94-year-old prime minister of Malaysia, and his perennial presumptive heir, Anwar Ibrahim, joined forces in 2018 to oust a governing party to which both had once belonged. That party, the United Malays National Organization, known as UMNO, was at the center of the 1MDB scandal, the brazen looting of billions of dollars of Malaysia’s public funds.
But the unwieldy coalition that brought Mr. Mahathir and Mr. Anwar together crumbled on Monday.
After a flurry of meetings that had political analysts feverishly analyzing whose car was pulling up in which driveway, Mr. Mahathir submitted his letter of resignation as prime minister on Monday afternoon.
The move, however, did not appear to be designed to result in Mr. Mahathir actually giving up leadership of Malaysia, a job that he has held twice, analysts said.
Malaysia’s constitutional monarch accepted the resignation letter on Monday evening but then named Mr. Mahathir the interim prime minister, according to Mohd Zuki Ali, the nation’s chief secretary.
Vying political blocs in the country had earlier expressed support for Mr. Mahathir’s continuing as prime minister.
“The wonderful thing for Mahathir is that it is impossible for him to lose because heads he wins, tails he wins,” said James Chin, director of the Asia Institute Tasmania at the University of Tasmania.
It was a sleight of hand characteristic of Asia’s shrewdest veteran politician — and it left Malaysians breathless from the political machinations.
But with the governing coalition in tatters and rival political blocs furiously forming new alignments, the only constant in Malaysia on Monday was a sense of uncertainty. Could Mr. Mahathir have overplayed his hand?
Reflecting the jittery atmosphere, the Malaysian securities market took a hit, and Malaysia’s national bank issued a statement on Monday, saying it was “closely monitoring conditions in the financial markets.”
Mr. Mahathir’s unexpected resignation also raises questions about the future of political and economic overhauls in a country where Malay nationalist politics were promoted during Mr. Mahathir’s first term in office, from 1981 to 2003, and look to be gaining ground again.
“Malaysia will lose,” Mr. Chin said. “This means that it’s back to the same Malay supremacy politics that got the country into trouble in the first place.”
The diverse coalition that came to power in 2018, after voters rejected Prime Minister Najib Razak and his long-powerful UMNO party, placed a group of ethnically Chinese and other minority politicians in positions of prominence for the first time.
Malaysia is still struggling with the fallout of billions of dollars that were pillaged from a national investment fund, 1MDB, or 1Malaysia Development Berhad. Mr. Najib is accused of having orchestrated the looting.
Trials related to the 1MDB scandal are continuing and have drawn in forces as diverse as Goldman Sachs and Hollywood movie stars to Chinese officials and luxury handbag makers.
Now 72, Mr. Anwar was once a fiery leader of a Malay nationalist youth movement and served as deputy prime minister during Mr. Mahathir’s first, 22-year tenure as prime minister. But Mr. Mahathir purged his deputy, and Mr. Anwar spent years in and out of jail on sodomy convictions.
The sex act is illegal in Malaysia, but rights groups said Mr. Anwar’s jailing was politically motivated.
Mr. Mahathir eventually settled on Mr. Najib as a protégé. Mr. Najib served nine years as prime minister, until the 2018 elections that returned Mr. Mahathir to power, leading a coalition that included liberal Chinese politicians and Islamists.
On Monday morning, Mr. Anwar met with Mr. Mahathir, and hinted that all was well.
“I was touched by his attitude and principle,” Mr. Anwar said, recounting that Mr. Mahathir had reaffirmed that he “would not bow to the groups that want to grab power without setting any reform agenda.”
Then a couple hours later, Mr. Mahathir submitted his resignation letter.
The afternoon brought more twists and turns. Mr. Mahathir’s party, the Malaysian United Indigenous Party, quit the governing coalition. Then Mr. Mahathir announced that he had quit his own party, adding to the political intrigue. He is expected to meet with Malaysia’s king in the late afternoon.
Lim Guan Eng, Malaysia’s finance minister and the leader of a Chinese-majority party that pledged on Monday to continue backing Mr. Mahathir, released a statement saying that the prime minister had resigned not because he wanted to outmaneuver Mr. Anwar but because he was disgusted with members of his coalition who had plotted to join with UMNO.
In neighboring Singapore, Goh Chok Tong, the former prime minister of Singapore, took to Twitter to express his astonishment with the political tumult in Malaysia.
“It is a privilege for a septuagenarian to be able to enjoy nature and the simple pleasures of life, unlike nonagenarian Mahathir,” Mr. Goh wrote.