Then followed a series of political alignments, realignments and yet more realignments, with every half-day seeming to bring a new political reality.

By Saturday morning, it appeared that the remains of the Alliance of Hope, which Mr. Mahathir had cobbled together out of disparate political forces — including Malay nationalists, Chinese reformists and liberal Islamists — had coalesced around the nonagenarian ruler yet again.

But with horse-trading still continuing, the king announced on Saturday afternoon that he had met with the nation’s lawmakers and determined that the majority supported Mr. Muhyiddin’s candidacy for prime minister.

“I would like to express my thanks, thanks to Allah, that I have been given the appointment,” said Mr. Muhyiddin, 72.

Mr. Muhyiddin, who has stated that he is “a Malay first” in multiethnic Malaysia, is a leader of the Malaysian United Indigenous Party, which Mr. Mahathir had helmed until less than a week ago. As the Alliance of Hope fractured, the party stepped across the divide to partner with the United Malays National Organization, or U.M.N.O., the corruption-dogged party that had dominated Malaysian politics for decades.