KUALA LUMPUR, Malaysia — Mahathir Mohamad, who presided over an era of strongman rule in Malaysia a generation ago, was sworn in again as the country’s prime minister on Thursday, defusing a potential constitutional crisis and ousting the coalition that has run the nation for decades.
Mr. Mahathir, 92, who left the bloc he helped to build and led a broad coalition to a historic election upset, was sworn in after a day of tense uncertainty in Malaysia. The country had not seen a transfer of power to the opposition since its independence from Britain in 1957.
Despite the verdict of voters, who officials said gave Mr. Mahathir’s coalition an outright majority in Parliament, the entrenched government of Prime Minister Najib Razak appeared for much of the day to be holding out hope that Malaysia’s monarch might refrain from asking Mr. Mahathir to form a government.
As the leader of a broad opposition coalition, united primarily by outrage over the towering list of corruption accusations against Mr. Najib, Mr. Mahathir has promised to rebuild government institutions and fight corruption. He has also vowed to lead a more inclusive government beyond the country’s ethnic Malay Muslim majority that Mr. Najib catered to.
But even as Mr. Mahathir announced a democratic victory early Thursday, the country’s political fate was temporarily in the hands of its king, Sultan Muhammad V.
Under the Malaysian Constitution, the mostly ceremonial and rotating role of monarch is still empowered to swear in new prime ministers — and hours after the election results were made official, the king still had not moved to do it.
In his address Thursday morning, Mr. Mahathir declared that it was time for Malaysia to honor “the rule of law,” and declared that the king should put him in office by 5 p.m.
“Any delay will mean that we have no government, and when you say you have no government, you have no law, you have no constitution,” Mr. Mahathir said. “You don’t have all the institutions which are created to give form to the government of this country.”
In contrast, Mr. Najib ws grim during his national address Thursday morning. He took no questions from reporters. And even as he said he would “accept the verdict of the people,” he also suggested that the final result might be in doubt, and it would be up to the king to decide who would be sworn in.
“This was an election which saw a tough fight,” he said. “But this is a manifestation of the democracy we practice.”
The final announcement did not come until after 9:30 p.m. Thursday.
Mr. Mahathir had headed to the palace in formal attire for a swearing-in ceremony, but also brought along a team of constitutional lawyers. There were several hours of discussions before the palace announced it would ask him to form a new government.
The vote was a rejection of Mr. Najib’s coalition, the United Malays National Organization, which after six decades in power had come to represent corruption and the arbitrary use of authority to maintain power.
Malaysia has three main ethnic groups, Indians, Chinese and Malays, who are largely Muslim and make up the majority of the country’s 31 million people.
Since the country gained independence from Britain in 1957, it has been ruled by the United Malays National Organization, a rare ruling party that is based on the principle of advancing a single ethnic group. Mr. Najib’s father and uncle were early party leaders and both served as prime minister.
UMNO, as the party is known, has long promoted the idea of providing special advantages to Malays, including providing a set number of places in and universities for Malay students. Until Wednesday, UMNO and its broader coalition, the National Front, had never lost a parliamentary majority.
As prime minister and UMNO’s leader from 1981 to 2003, Mr. Mahathir repeatedly won the support of the Malay majority but he also gained a reputation as a builder who established modern-day Malaysia.
The Petronas twin towers in Kuala Lumpur, which for a time were the world’s tallest buildings, came to symbolize his effort to put Malaysia on the map.
In Wednesday’s vote, he was able to recapture some of the ethnic Malay support that he once enjoyed while uniting members of the opposition who were once his foes in their common quest to end what they saw as Mr. Najib’s corrupt rule.
Mr. Mahathir now faces the challenge of maintaining this broad alliance while reorganizing government spending and strengthening the rule of law.
At his morning news conference, Mr. Mahathir pledged to seek a royal pardon for the former opposition leader, Anwar Ibrahim, who is now serving his second prison sentence for sodomy and is scheduled to be released in June.
He was once Mr. Mahathir’s deputy prime minister, and Mr. Anwar’s supporters hope he can someday become prime minister himself. But he must have a royal pardon before he can run for Parliament again. That process requires many months and the king’s approval.
For now, Mr. Anwar’s wife, Wan Azizah Wan Ismail, is expected to be deputy prime minister, the second-highest post in the new government.
Mr. Mahathir has also said he would clear the way for the criminal prosecution of Mr. Najib, who is accused of taking hundreds of millions of dollars in government funds.
Mr. Najib has been embroiled for years in a scandal a involving billions of dollars that disappeared from a government investment fund that he once headed, 1Malaysia Development Berhad. The United States Justice Department concluded that $3.5 billion from the Malaysian fund was laundered through financial institutions in the United States and spent on items like expensive real estate, jewelry, paintings and the production of movies.
Cynthia Gabriel, executive director of the Center to Combat Corruption and Cronyism in Kuala Lumpur, said she expects the new government to open a proper investigation of Mr. Najib and the missing funds, and to begin cooperating with the Justice Department and other foreign investigations.
“There is a lot of work to be done to undo the years of unbridled power,” she said. “But for now, the power has been returned to the Malaysian people, as we have ushered in a two-party system.”
The ouster of Mr. Najib was all the more striking in a region where the solidification of autocratic rule, including arbitrary killings and imprisonment as well as crackdowns on the media, has seemed to be the rule.
From President Rodrigo Duterte’s deadly drug war in the Philippines, to ethnic cleansing of Rohingya Muslims in Myanmar, and President Hun Sen’s campaign to crush Cambodia’s democratic opposition, it has been a tough period for democracy and human rights throughout Southeast Asia.
Addressing China’s extensive influence and investment in Malaysia, Mr. Mahathir said his new government would need to study agreements made by Mr. Najib and that he was concerned about the size of Malaysia’s debt to China.
But Mr. Mahathir said that he was not opposed to China’s Belt and Road program to build infrastructure projects abroad, and that he had personally written to China’s president, Xi Jinping, to encourage him to build rail lines.
“As for the Belt and Road program, we have no problem with that, excepting of course we would not like to see too many warships in the area,” he said. “Warships attract other warships.”
Mr. Mahathir’s coalition, Pakatan Harapan, overcame Mr. Najib’s advantages of money and incumbency on Wednesday and won at least 122 seats in Parliament, 10 more than needed to form a government.
James Chin, a Malaysian who is the director of the Asia Institute at the University of Tasmania, said Mr. Mahathir was elected as a “transitional figure” to rebuild the country’s government and pave the way for another onetime protégé, Mr. Anwar, to succeed him.
“His role is to put the institutions back in place, and he is supposed to keep the seat warm for Anwar Ibrahim,” Mr. Chin said.
Sophie Lemiere, a postdoctoral fellow at Harvard University who is writing a book about Mr. Mahathir, said the election gave him the chance to correct mistakes of his earlier rule.
As prime minister the first time around, he earned a reputation as an autocrat who jailed his opponents — some of whom supported this time.
Now, in his encore as prime minister, he can create a kinder legacy for himself as an advocate of democracy, justice and human rights.
“Adopting this vernacular and these new concepts is a way to rewrite history and rewrite his 22 years of power,” she said. “He can say, ‘I was never a dictator. Do you know any dictator who gets elected again?’ ”
Sharon Tan contributed reporting.