Thai Prime Minister Prayut Chan-O-Cha survived a legal challenge Wednesday over his living arrangements that could have seen him thrown out of office, in a court ruling that prompted anger among thousands of pro-democracy protesters.

The kingdom's nine-judge constitutional court ruled that Prayut -- already under pressure after months of street protests calling for him to quit -- was not guilty of conflict of interest by living in an army residence after leaving the military.

Thailand's constitutional court ruled that Prime Minister Prayut Chan-O-Cha (C) was not guilty of conflict of interest by living in an army residence after leaving the military
Thailand's constitutional court ruled that Prime Minister Prayut Chan-O-Cha (C) was not guilty of conflict of interest by living in an army residence after leaving the military AFP / Lillian SUWANRUMPHA

Thousands of protesters defied a warning from the court to respect its ruling, taking to the streets to condemn the judgment as unjust.

The court ruled that Prayut's status as prime minister entitled him to live in the military house even though he stepped down as army chief in 2014.

"The status of General Prayut Chan-O-Cha as prime minister and defence minister remains unchanged," the head judge said.

Inflatable toy ducks have become a symbol of the Thai pro-democracy protests calling for the prime minister to step down
Inflatable toy ducks have become a symbol of the Thai pro-democracy protests calling for the prime minister to step down AFP / Jack TAYLOR

Though widely expected, the ruling angered the protest movement that has shaken Thailand since July calling for Prayut, who came to power in a 2014 coup, to quit.

Some 5,000 protesters massed at a major intersection in northern Bangkok. The rally included uniformed high school students wearing hair clips shaped like rubber ducks, a symbol of the pro-democracy movement.

"I'm not surprised because I think the court received the directive from the top. The court is not fair," Reeda, 26, a graduate student, told AFP as demonstrators gathered at Lat Phrao intersection.

Rubber ducks have become a symbol of Thailand's pro-democracy movement
Rubber ducks have become a symbol of Thailand's pro-democracy movement AFP / Lillian SUWANRUMPHA

"In the past they always decide decisions that contrast with the feeling of the people."

Thousands took to the streets of Bangkok on Wednesday night
Thousands took to the streets of Bangkok on Wednesday night AFP / Lillian SUWANRUMPHA

On the eve of the decision the court warned against "vulgar" criticism of its work, but this did not deter protesters, who daubed slogans against the court and Prayut on the road.

"I know the PM will always be OK -- it's like the same mafia running things in Thailand. But many people know the truth," Chat, a 60-year-old retiree, said.

Prominent student leader Parit "Penguin" Chiwarak addressed the crowd on a stage with a mocked-up model of the constitutional court as a backdrop.

Pro-democracy activist Parit "Penguin" Chiwarak burns pieces of paper featuring headshots of judges on the Constitutional Court
Pro-democracy activist Parit "Penguin" Chiwarak burns pieces of paper featuring headshots of judges on the Constitutional Court AFP / Lillian SUWANRUMPHA

"I propose that Thailand has no need for this constitutional court. They must all go. They have thwarted democracy far too many times," he told the rally.

"(The judges are) appointed by Prayut so they work for Prayut not us the people. They no longer have legitimacy in our justice system."

The case against Prayut was brought by the main opposition party Pheu Thai and if it had succeeded the PM and his cabinet would have been thrown out of office.

The court said the military had changed the status of the residence from an army house to a guest house in 2012 "so technically, the defendant's no longer living inside an army house".

The premier has previously argued his family must stay at the army house on a military base for security reasons.

After the verdict, government spokesman Anucha Burapachaisri said Prayut was "working as usual and following his official schedule as normal".

He appeared relaxed ahead of the decision, and toured a coconut farm on Wednesday, sending his lawyers to hear the verdict on his behalf.

Titipol Phakdeewanich a political scientist with Ubon Ratchathani University, said Prayut's victory was little surprise.

"They always try to find a legal loophole to protect him," he told AFP.

Chulalongkorn University political scientist Thitinan Pongsudhirak echoed the view.

"Anyone who's followed Thai politics for the past 15 years will think it's a foregone conclusion... because the constitutional court has been so politicised since 2006 that it does not engender public trust," he told AFP.

The pro-democracy movement is facing legal action of its own, with five key leaders charged on Monday under Thailand's strict royal defamation laws -- the first time they have been used in two years.

As well as calling for Prayut to go, protesters also want a rewrite of the army-drafted constitution and for reforms to the monarchy -- a taboo-smashing demand in a country where the ultra-wealthy royal family has long been untouchable.