Tuesday was a dramatic day in Thailand as parliament staved off a potential political crisis by finally voting for a new prime minister as one of the country's most polarizing figures returned from a 15-year self exile.
Thai lawmakers chose real estate tycoon and political newcomer Srettha Thavisin of the populist Pheu Thai party to be the country's 30th prime minister -- an outcome that ended three months of deadlock but one that saw the party enter into a governing coalition with its longtime military enemies.
Srettha, 60, received 482 votes out of a possible 747 in both houses of parliament, far more than the majority needed to secure the premiership.
The return of Thaksin Shinawatra, the ousted former prime minister of Thailand and patriarch of the Pheu Thai political juggernaut, added a new layer of intrigue, with some supporters welcoming his return and others less sure of what the future will bring.
Some analysts say his return was part of a wider arrangement with the country's powerful conservative and royalist establishment that involved a reduced jail term or possible pardon in exchange for keeping the election-winning Move Forward Party from enacting its reformist policies that targeted the heart of this establishment.
So why is Thailand's prime minister-elect not the leader of the election-winning party? And why did Thaksin's party do a deal with the same military clique that ousted him and his sister Yingluck in coups?
Why is the winning Move Forward party not in power?
The first thing to know is that throughout much of its coup-prone modern history, Thailand has been run by a small but powerful clique that maintains deep ties to the military, royalist and business establishments.
In recent years, that establishment has seen its biggest challenge in decades, with young people calling for wide-reaching reforms.
In May's election, progressive parties swept the board with voters delivering a powerful rebuke of the military-backed leaders that have ruled Thailand for nearly a decade since a 2014 military coup.
It was also the first time a party linked to Thaksin had lost an election in more than two decades.
Newcomers, the Move Forward Party, had gained a huge following among young Thais for its reformist platform, which included changes to the military, the economy, the decentralization of power and radical plans to amend the country's strict lese majeste laws despite the taboo surrounding any discussion of the royal family in Thailand.
Hailed as a "game changer" by analysts, that platform proved popular not just among young Thais but a wider pool of society tired of Thailand being run by the same old forces making little progress on issues such as improving fairer wealth distribution, the economy and job prospects.
Move Forward pulled off a stunning election win but failed to get enough seats to form a government outright. It formed a coalition with other like-minded parties, including runners up Pheu Thai.
The Senate proved the first roadblock. Under Thailand's constitution, which was written following the 2014 military coup, the unelected Senate is stacked with military appointees and maintains an outsized say in who can form a government and become prime minister.
Many conservative lawmakers also took issue with Move Forward's pledge to reform lese majeste and blocked party leader Pita Limjaroenrat from becoming prime minister in the first parliamentary vote in July.
The Constitutional Court then suspended Pita after accepting cases accusing him of violating election law for allegedly holding shares in a media company -- allegations he denies.
The progressive coalition soon broke apart and Move Forward stepped aside to allow its alliance partner Pheu Thai to pick up the reins and attempt to form the next government instead.
Pheu Thai then cut ties with Pita's party, effectively sidelining the winning party, citing Move Forward's pledge to introduce royal reform, and vowed not to touch lese majeste or include the party in its new coalition.
A deal between old foes
Pheu Thai had campaigned to get the military out of politics and repeatedly said it would not form an alliance with pro-military parties.
In the end it did just the opposite.
In a bid to secure enough votes for Srettha to get into office, it struck a deal with two military-backed parties linked to a coup that toppled a Pheu Thai government headed by Thaksin's sister Yingluck Shinatwatra in 2014.
A deal between Pheu Thai and parties aligned with the military was once unthinkable.
Until this year, political parties allied to Thaksin had won the most seats in every election since 2001, but have struggled to hold on to power due to the military exerting its influence, whether through coups or other means.
"Pheu Thai's relationship with the military has been contentious and adversarial until now," said Thitinan Pongsudhirak, a professor of political science at Chulalongkorn University.
"Its ironic to me that Thaksin, and Pheu Thai under Thaksin now, is actually working with and helping the very military leaders who put them down before, who deposed them."
Political observers have speculated that the deal was a way for the two forces that have long dominated Thai politics to remove Move Forward from the equation and ensure the status quo was not in jeopardy by its proposed reforms.
"Another trade off [in the deal] is that Pheu Thai would lead the government and keep Move Forward from introducing reforms of the monarchy and military," Thitinan said.
Thaksin's return adds another twist
The return of Thaksin added more speculation as to the future direction of Thai politics.
The head of the famed political dynasty and a former owner of Manchester City Football Club was prime minister from 2001 until 2006 when he was ousted in a military coup. He returned to Thailand briefly before fleeing the country in 2008 over a corruption conviction.
A divisive figure, Thaksin is a billionaire telecommunications mogul who built his political power on policies popular with Thailand's rural poor, who made up the majority of the country's population. But his policies were anathema to the country's rich elites and conservatives who accused Thaksin of being a dangerous and corrupt populist.
His ouster spurred a protest movement that developed over the years into widespread "red shirt" demonstrations that were violently put down in 2010.
Despite Thaksin's physical absence, he has retained an outsized influence on Thai politics.
Analysts say Thaksin may have struck a deal with Thai authorities for his return -- given his court convictions and the charges against him -- in exchange for a reduced jail term, lenient treatment, or a possible pardon.
"It's in Thaksin's nature to make deals," said Thitinan. "It makes no sense for him to be roughing it in jail until he's 83. There has to have been some understanding."
Thaksin was sentenced to eight years on corruption charges on his arrival and was held "for quarantine in a special room" before being transferred to hospital Wednesday due to chest tightness, high blood pressure and low oxygen levels, the Thai Corrections Department said.
The department said his underlying heart disease could not be treated at a prison hospital and that he would need specialist care.
The means the likelihood of him actually seeing the inside of a jail cell for now is small.
What next?
Prime minister-elect Strettha needs to be endorsed by Thailand's King Vajiralongkorn before he can be sworn in.
Before entering politics, the wealthy property developer, who is not a member of parliament, worked as an executive for Procter & Gamble in Thailand and later founded real estate company Sansiri with his brother.
According to the Bangkok Post, the company posted revenue of 34.9 billion baht ($999 million) last year.
His wife is a doctor specializing in anti-aging medicine, the paper reported.
Speaking to CNN before the May election, Srettha said he is not Thaksin's man and was keen to focus on fixing Thailand's income inequality, promote LGBTQ+ rights including same-sex marriage, root out corruption and put the country back on the world stage.
"I want to be a prime minister who can make the difference," Srettha previously told CNN.
But with an 11-member coalition that includes bitter rivals, it's unclear whether Srettha and Pheu Thai will be able to govern effectively.
Some analysts say even this alliance would be better than the military-backed administration of Prayut Chan-o-cha that preceded it.
"The bar is very low," said Thitinan. "Pheu Thai does know the business of government, they will know how to get some things done... It will be unruly with corruption allegations but it might get Thailand moving more than before."
Forgotten in this political chaos, however, are the millions of voters whose chosen party was prevented from forming a government following democratic elections.
"The big picture is really the crisis of Thai democracy," Thitinan said.