Victory for the retired general was all but guaranteed by the support of the handpicked 250-member Senate
Thailand's junta chief Prayut Chan-ocha was elected late on Wednesday as the kingdom's first civilian prime minister since the 2014 coup he led, in a vote by a parliament stacked with appointed allies of the conservative, arch-royalist army.
Prayut swept aside his sole challenger, the charismatic 40-year-old billionaire Thanathorn Juangroongruangkit who led the anti-military bloc, garnering 500 votes to his rival's 244.
Victory for the retired general was all but guaranteed by the support of the handpicked 250-member Senate and the late swing of key secondary parties into an army-affiliated coalition after frantic behind-the-scenes talks.
The Senate, which was appointed by the junta, includes scores of military officers and loyalists -- many identifiable as they read out Prayut's name by their short serviceman's haircuts.
His election completes a journey for the 65-year-old Prayut from gruff army chief who toppled the last civilian government to prime minister, with claims to legitimacy after an unexpectedly strong showing from his army-linked party in a March general election.
Yet Thailand remains bitterly divided after 13 years defined by coups, violent street protests and short-lived civilian governments.
At their root is a rivalry between an arch-royalist conservative establishment and pro-democracy parties supported by many in the lower and middle class as well as young people wearied by the rule of hectoring generals.
Critics say Prayut represents a narrow elite and lacks the vision to govern as a civilian leader, having failed as junta leader to reboot Thailand's economy, bridge its chasmic inequality or heal the ulcerous political divisions.
After the count, a defiant Thanathorn vowed to "work harder" to build Thailand's pro-democracy front.
"Dictators cannot resist the wind of change forever," he told reporters.
With his withering critiques of the military and its conservative politics, Thanathorn is seen as a serious long-term threat to the establishment.
But he is besieged by court cases that could see him banned from politics and even jailed. He could not even enter the parliament building on Wednesday because of the legal suits against him.
Meanwhile, lawmakers from Pheu Thai, the political machine tied to self-exiled premier Thaksin Shinawatra, took advantage of the rare opportunity to criticise Prayut during the televised proceedings.
Prayut has "obsolete ideas" that will endanger the country, MP Cholnan Srikeo said.
But supporters say Prayut is a stabilising figure who can steer Thailand away from its perennial political crises.
"I am going to vote for General Prayut," said Mongkolkit Suksintharanon, head of the Thai Civilised Party, a junta ally. "Thanathorn has no experience."
The March election was cast as a choice between a tethered democracy led by a junta in civilian clothes and parties aligned with Thaksin.
But an unexpected third force emerged, led by the billionaire auto parts scion Thanathorn.
His Future Forward Party won 81 seats to become Thailand's third-largest party, emerging from nowhere to scoop up millions of votes.
Thanathorn was put forward on Tuesday as the anti-junta bloc's only choice for premier, despite the odds against him.
Standing for prime minister was always going to be "futile", said Karen Brooks, an Asia expert at the Council on Foreign Relations.
But "it serves to further raise his profile... and perhaps raise the cost to the military and its allies as they proceed with efforts to destroy him," she added.