As results poured in from polling stations around Malaysia on the night of May 9, with one parliamentary seat after another falling to the opposition, a stunned Prime Minister Najib Razak stared defeat in the face.
There was no hiding the fact: the Najib-led Barisan Nasional coalition that had run Malaysia for the six decades since its independence from Britain had lost the election.
Voter anger over a goods and services tax, as well as allegations of corruption that had swirled for years around Najib's government and the apparently lavish lifestyle of his wife, had finally taken its toll.
A consultant who was in Najib's office as the reality of the defeat sank in said the prime minister was stunned. "When he knew that the numbers were not on his side, Najib broke down," he said.
Explaining Najib's shock on election night, one political strategist with ties to the now-defeated government said it was not unusual for him to be out of the loop when there were unwelcome developments.
"Najib lives in a bubble," he said. His advisers "don't accept others' views," he added. "They don't listen to bad news."
Najib's remove, and the disarray in his camp during the campaign and the election, was pieced together from interviews with about a dozen political operatives and members of the ruling coalition and the opposition.
Trump's favorite prime minister
The electoral defeat was a humiliating turn for Najib, who had ruled for almost a decade and had projected himself as a statesman who enjoyed a warm relationship with Chinese President Xi Jinping, and played golf with US presidents. Donald Trump showered him with praise during a White House visit last year, and according to local media once gave Najib a photograph of them together inscribed with the words: "To my favorite prime minister."
Dubbed "The Survivor" on the cover of a magazine before the election, Najib, 64, had for three years weathered a scandal over the billions of dollars that went missing from the state fund 1Malaysia Development Berhad (1MDB). He consistently denied wrongdoing in connection with 1MDB.
Najib went into the poll confident of victory, according to the interviews with politicians and party officials. But his week went off-script quickly and — despite frantic efforts — he failed to pull it back.
Reuters was unable to reach Najib or any close aides for comment.
An official who worked on Najib's campaign said his camp had been sure of victory several days before the vote.
That confidence sagged as election day loomed with mounting evidence that momentum was with the opposition.
The political strategist said that two cabinet ministers were so unnerved that they stopped country-wide campaigning to concentrate on defending their own parliamentary seats.
Despite growing evidence of huge turnouts at opposition rallies, the ruling coalition remained confident of victory, even if with a weaker mandate, banking on its traditional Malay vote base.
Ten hours before polling stations opened, Najib went on national television and made voters a trio of promises.
If they returned him to power, he said, his government would scrap income tax for the young, declare two extra public holidays and make toll roads free for a few days during the Islamic festival of Eid.
"It was desperation," said the campaign official.
Opinion polls showed that voters were angry over living costs after the introduction of the goods and services tax, but they were also disgusted by the allegations of corruption surrounding Najib.
"It was conflated with so many other things — with higher costs of living, with inflation, with the goods and services tax," said Khairy Jamaluddin, the youth and sports minister in Najib's government, explaining the public discontent. "But at the root of it was scandal."
A senior official in one of the opposition parties said that Barisan Nasional had been wrong to count on votes from the country's majority ethnic Malays on the basis of the affirmative-action policies that benefit them.
That shortcoming was underlined by the large crowds turning out for rallies for the opposition's Mahathir Mohamad, the 92-year-old former prime minister, in predominantly Malay areas that had long been bastions of support for the ruling coalition.
"Sometimes on the ground, we were telling ourselves this is too good to be true," said one leader of Mahathir's Pakatan Harapan, or Alliance of Hope.
On election day, opposition party officials said they were sure of victory by early evening thanks to results that their representatives at polling stations had passed on.
The mood was jubilant in the opposition camp as it became clear its candidates had beaten leading Barisan Nasional politicians and made significant gains across the country.
By midnight, Mahathir felt confident enough to declare victory.
Najib did not concede, however, apparently having recovered his composure as the night went on.
Khairy visited Najib at his house that night and said the prime minister was "calm" and "poised," but that the people around him were "stunned, shocked and somber."
When the Election Commission eventually announced the result, hundreds of jubilant Mahathir supporters waved flags and cheered in central Kuala Lumpur.
The next day, Mahathir, who was once Najib's mentor and later his bitter adversary, was sworn in as prime minister.
Mahathir's challenges for the multi-ethnic nation are substantial: how to keep together an alliance made up of former foes, and implement populist measures and reforms without disrupting economic growth — even as he has promised to cede power to Anwar Ibrahim, the opposition leader jailed by Najib.
Mahathir's immediate attention appeared to focus on Najib. During the election campaign, Mahathir had vowed to hold Najib to account for his alleged role in the disappearance of billions of dollars from a government fund.
As he assumed power last week, he said that those who had broken the law would be punished.
Meanwhile, Najib's estranged step-daughter, Azrene Ahmad, took to social media to hail "the end of an era of tyranny."
Anger at the airport
With Mahathir in power, speculation swirled about Najib's future. Would Mahathir have him arrested? Would Najib try to leave the country?
On the Saturday after the election, an angry crowd gathered outside a small airport near Kuala Lumpur. Online, another 30,000 people tuned into a Facebook live event, streaming from the airfield entrance.
A report had leaked that Najib and his wife, Rosmah Mansor, were going to try to leave Malaysia aboard a private plane.
"Stop them running away!" said one watcher of the Facebook Live event.
Amid the commotion at the airport, Najib announced on social media that he would indeed be leaving, to take a holiday overseas. But he and his wife never showed up at the airport.
What Najib hadn't realized then was that, just minutes before his announcement, the Immigration Department had issued a statement that Najib and Rosmah were barred from leaving the country — a final humiliation for the former prime minister.
Later that day, a somber Najib appeared at a news conference that appeared to signal the end of his political career.
Struggling to get a microphone to work, he put on a brave face as he announced that he was resigning as leader of both his political party, the United Malays National Organisation (UMNO), and Barisan Nasional.
"Anyone who is the leader and failed, it is the responsibility of that person to accept defeat. With an open heart, I accept it," he said.
Looking back at the evening of the election, Khairy, the Barisan Nasional lawmaker, discounted speculation that Najib had been hoping to find some way out of his predicament. Once the results had sunk in, Najib's priority had been figuring out how to achieve an orderly transition, he said.
"There were a lot of concerns that he was going to declare martial law, emergency rule, not hand over power," Khairy said. "Those were never ever options that were even discussed, thought or entertained in any way. It was just about accepting it and how we would concede."
Now, without Najib at the helm, the priority for the former ruling coalition was figuring out how to become the opposition for the first time, Khairy said.
"We were in a state of collective denial," he said, adding that the coalition had misunderstood the anger of the population. "We were too drunk on our own Kool-Aid, and this is a sobering lesson for us which we'll remember for the rest of our lives."
Tom Westbrook and A. Ananthalakshmi of Reuters reported from Kuala Lumpur.