Thailand's ruling junta took an unexpected lead in the country's first election since a 2014 coup with more than 90 percent of ballots counted, putting it on course to return to power at the expense of the kingdom's pro-democracy camp.
Sunday's election was held under new laws written by the military to smooth its transformation into a civilian government.
While it had set the rules of the game in its favour, analysts had not expected the party to win the popular vote, given mounting anger at junta rule and due to the enduring popularity of Pheu Thai, the party of ex-premier Thaksin Shinawatra.
The army-linked Phalang Pracharat party, which wants junta chief Prayut Chan-O-Cha to return as premier, gained more than 7.3 million votes with 91 percent of ballots tallied, according to the Election Commission -- nearly half a million more than Pheu Thai.
The EC said it would announce full results on Monday, including the numbers of lower house seats won by each party.
The election pitted a royalist junta and its allies against the election-winning machine of billionaire Thaksin -- who was toppled in a 2006 coup -- and featured an unpredictable wave of millions of first-time voters.
There was a high turnout as voters flocked to schoolyards, temples and government offices across the nation, their enthusiasm fired by years of denied democracy.
The junta has pledged to rescue the kingdom from a decade-long treadmill of protests and coups.
The election commission's announcement late Sunday diminished prospects of a pro-democracy alliance nudging it from power. But still supporters clung on in hope.
"Let's wait until the counting is finished," said Savitree Yodchomchin, 58, outside the Bangkok headquarters of Pheu Thai party, where a party atmosphere earlier among the cluster of supporters had soured.
"I am anxious," said Wipa Ployngam, 53, a supporter of the anti-junta Future Forward party.
"I'll stay here all night until everything becomes clear."
Fears of the potential for foul play ricocheted across social media as results came in -- a reflection of the lingering mistrust between rival camps, and disbelief that a much-pilloried junta could have won a popularity contest against Pheu Thai.
"Thai people come to vote because they want change," said Somkid, 64, a Pheu Thai voter who gave only one name.
"If there is any vote rigging there will be protests."
- Royal message -
Sunday's crunch vote was foreshadowed by a cryptic last-minute warning from King Maha Vajiralongkorn to support "good" leaders to prevent "chaos".
Thailand is a constitutional monarchy and the palace is nominally above politics. But the institution retains unassailable powers and is insulated from criticism by a harsh royal defamation law.
The day was framed by the palace statement, which added further intrigue to an election that repeatedly threatened to tip into chaos before a single ballot was cast.
It reiterated comments by late king Bhumibol Adulyadej from 1969 calling for voters to "support good people to govern the society and control the bad people" to prevent them "creating chaos".
While King Maha Vajiralongkorn gave no further clues as to who those "good people" might be, the phrase -- "khon dee" in Thai -- is habitually attached to royalist, establishment politicians.
Another royal command in February torpedoed the candidacy of the king's elder sister Princess Ubolratana for prime minister of a party linked to Thaksin.
That party was dissolved earlier this month, crippling the Shinawatras' electoral strategy.
Thaksin has lived in self-exile since 2008, but he looms large over Sunday's election. His affiliated parties have won every Thai election since 2001, drawing on loyalty from rural and urban poor.
- Junta rises -
Junta chief Prayut toppled the civilian government of Thaksin's younger sister Yingluck in 2014.
The army and its allies in the Bangkok elite loathe the Shinawatras, accusing the clan of toxifying Thai politics and society with money, nepotism and graft.
The Shinawatras say they have simply recognised the economic and democratic aspirations of Thailand's majority.
In Bangkok Sudarat Keyuraphan, a Pheu Thai prime ministerial candidate, said the party was eyeing a coalition but vowed "we will not join" any supporters of Prayut.
But with 250 votes of the appointed senate in hand, Phalang Pracharat needed just 126 lower house seats to secure a parliamentary majority, even if it does not carry the popular mandate.
If the early results play out on Monday, it appears set to comfortably cross that line.
Pheu Thai needs 376 lower-house seats to command an overall majority.
The telegenic 40-year-old billionaire Thanathorn Juangroongruangkit and his Future Forward party were also set for a strong showing, taking over five million votes for their acerbic anti-junta positions.
Thanathorn's social media pull appeared to have carried into the polling as his party galloped ahead in several Bangkok seats.
But it was gloom for the Democrats, Thailand's oldest party, who looked on course for a drubbing, prompting their leader Oxford-educated Abhisist Vejjjajiva to resign late Sunday.