BANGKOK -- Thailand's highest court on Wednesday acquitted Prime Minister Prayuth Chan-ocha of breaching ethics clauses in the country's constitution, allowing him to stay in his job.

The constitutional Court ruled on a complaint brought by the Pheu Thai party, the largest opposition grouping in Parliament, that Prayuth had broken the law by continuing to live in his military residence after he retired as army commander in September 2014.

The complaint alleged that he broke constitutional articles barring government ministers from receiving special benefits from state agencies or enterprises because that would amount to a conflict of interest. If a minister is found guilty of violating ethical standards, the official is to be disqualified and forced to step down.

The nine-judge panel agreed with an army explanation that retired senior officers such as Prayuth are allowed to stay in army housing in recognition of their service. The judges ruled unanimously in Prayuth's favour.

The ruling comes as Prayuth has been dealing with a persistent student-led pro-democracy movement that has been holding frequent well-attended rallies demanding that he and his government step down, charging that they came to power illegitimately.

Even before the court convened Wednesday. the protesters had called a rally to respond to the verdict.

"Thailand's justice system has completely lost its integrity. The court's verdict today shows they look down on the people. This will fuel people's anger and be the condition that drives our rallies to a higher level," a protest leader, Parit "Penguin" Chiwarak, told The Associated Press.

The rally attracted several thousand people, and like many other recent ones had a carnival atmosphere at times. But there was also an angry tone, as when Parit tore up and burned a book written by one of the judges. He said he did not mean to disrespect the book or its contents, but destroyed it to show he no longer respected the author, Nakharin Mektrairat, who in the past decade has become a prominent defender of conservative Thai ideology.

As army commander, Prayuth led a coup in May 2014 that ousted an elected government led by the Pheu Thai party. He then headed the junta that ruled for five years and was also prime minister in the military-guided government.

A general election last year brought to power a proxy party established by the military, which with its allies selected Prayuth to serve again as prime minister. The ongoing protests charge that the 2017 constitution established under military rule gave the proxy Palang Pracharath Party an unfair advantage in the election.

When Prayuth and several of his Cabinet ministers faced a censure debate in Parliament in February, opposition leader Sompong Amornwiwat of the Pheu Thai party raised the issue of whether Prayuth had acted illegally by continuing to live at his army residence at a base in Bangkok.

Prayuth's defence has been that the official residence of the prime minister is undergoing renovation, and also that he faces security concerns.

The army argued on his behalf that his military housing is actually a VIP guest house, though critics suggest that if he did not pay at least for water and electricity, he may be breaking the law.

The court said that senior officers such as Prayuth were entitled to live in military housing as special guests in honour of their military careers. Deputy Prime Minister Prawit Wongsuwan and Interior Minister Anupong Paochinda were given the same privilege, former army chief Gen. Apirat Kongsompong declared before his retirement this past September. The court also said the current chief, Gen. Narongpan Jittkeawtae, had explained that the army's regulations allow it to pay for utilities and other necessary costs in such instances.

In the past 12 years, court rulings have ousted three Thai prime ministers.

The court, like the military, is considered a pillar of the country's royalist establishment, and the ultimate bulwark against threats to it. The three ousted politicians were associated with a former prime minister, populist billionaire Thaksin Shinawatra, who was ousted by a 2006 military coup after being accused of abuse of power, corruption and disrespect to the monarchy.

The court's rulings have generally been favourable to Thaksin's opponents and hostile to his supporters, leading to criticism that it it is guided as much by politics as by law.