Thai Prime Minister Prayut Chan-o-cha has won a legal battle in a conflict-of-interest case that had been brought by opposition politicians and could have seen him thrown out of office.
The prime minister, who was under pressure from months of street protests, was accused of a conflict of interest because he remained in military housing despite his retirement from the army in 2014, months after overthrowing an elected government.
The nine-member constitutional court, however, unanimously ruled in his favor on Wednesday.
The head judge 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 "not guilty" verdict for the prime minister also means that he can stay in power.
"The status of General Prayut Chan-o-cha as prime minister and defense minister remains unchanged," the judge said.
"The plaintiff did not commit acts that constituted conflicts of interest. He did not seek personal gains, whether directly or indirectly, nor breach ethics," said the judge.
Prayut had said that he would respect the court's decision even if it ruled against him.
The court's decision is now widely expected to inflame anti-government protests across the country.
Thailand has been the scene of widespread demonstrations for reforms to the powerful monarchy since July, with protests breaking a long-standing taboo against criticizing the king and constitution, as well as growing calls for the removal of the prime minister.
On Sunday evening, thousands of protesters marched to a barracks belonging to Thailand's royal guards in the capital, Bangkok, demanding that King Maha Vajiralongkorn give up control of some army regiments.
In a statement, the protesters accused the king of having "expanded his royal prerogative in every way possible including [through] the military" and referred to the prime minister as the "royal puppet."
The current king succeeded his father, King Bhumibol Adulyadej, in 2016.