Thailand’s prime minister was removed from office Wednesday in an abuse-of-power court ruling that leaves a politically riven country in deeper danger of chaos and further violence.

The Constitutional Court decision marked a sudden and divisive swing in Thailand’s long-running and damaging power struggle. The ouster of Yingluck Shinawatra and part of her cabinet gashes Thailand’s executive branch at a time when the main parties in the fragile democracy have not been able to agree on elections or a way forward.

Over the past six months, Yingluck had faced numerous challenges to her rule, including street protests and a probe by an anti-corruption panel into a populist rice scheme that caused the state massive losses.

But the court decision Wednesday stemmed from a more obscure case, one involving the transfer of a senior civil servant three years ago. The court said the move had a “hidden agenda,” leading to a broader reshuffle of positions that helped a Yingluck relative become police chief.

“Transferring government officials must be done in accordance with moral principle,” the court said in its ruling, which was read aloud on national television for more than an hour.

The decision handed down by Thailand’s highest court was final and immediate, and it removed all cabinet members who held posts at the time of the personnel decision. The remaining cabinet members quickly appointed Niwatthamrong Bunsongphaisan as acting prime minister.

Amid the protests in Bangkok, Yingluck had maintained her popularity in rural areas. The divide between rural and urban voters has plagued Thailand for nearly a decade, since Thaksin Shinawatra — Yingluck’s older brother and the country’s first populist leader — was ousted as prime minister in a military coup in 2006.

Since then, a pattern has emerged in which rural voters return Thaksin-backed parties to power and courts summarily remove them. Since 2006, the Constitutional Court has twice dissolved Thaksin-supported political parties and three times toppled Thaksin-supported premiers, including Yingluck. Thaksin’s supporters, known as the red shirts, say the courts have become a partisan entity that wants to return power to Bangkok’s elites. Those who oppose Thaksin, though, say the telecom tycoon’s corruption and political meddling is undemocratic and is endangering the country. Thaksin has continued to advise Yingluck from political exile in Dubai.

Several hours after the ruling, Yingluck, 46, denied that she had done anything wrong and said her administration “never acted corruptly.”

The court said the removal of Thawil Pliensri as secretary general of the National Security Council was unconstitutional and was aimed at opening a position for a relative. A lower court said earlier this year that Thawil’s transfer was illegal and ordered his reinstatement.

Yingluck’s Pheu Thai Party said in a statement that the court decision amounted to a judicial coup and is part of a “conspiracy to topple the democratic ruling system.”

New elections are scheduled for July 20. The ruling adds to already formidable obstacles jeopardizing that plan. Thailand figures to be all the more rudderless without Yingluck, some analysts say, raising the prospect of fresh attempts by the anti-government movement to install its loyalists in power. If Yingluck’s supporters feel threatened, they, too, could descend on Bangkok, risking more violence in a replay of 2010 clashes.

A more promising scenario is that the court’s decision allows a brief reduction in tensions, appeasing anti-government protesters with Yingluck’s removal while also keeping the Pheu Thai Party temporarily in power.

“The question is whether the protesters will be satisfied with Yingluck’s ouster and return to the electoral system,” said Thitinan Pongsudhirak, a political scientist at Chulalongkorn University in Bangkok. “Or, will they continue to protest Yingluck’s successor? If they continue to do that and reject elections, then we are back in the same place, and maybe worse.”

Since November, more than 20 people have been killed in gunfire, grenade explosions and clashes with police. As protesters blockaded parts of Bangkok, pitching tents and erecting stages in front of intersections and luxury malls, Yingluck dissolved parliament and called a snap election. Protesters, though, turned the election into a street fight, blocking polling stations and preventing some candidates from registering. The election, held in February, was eventually nullified, and Yingluck remained in office as caretaker prime minister.

Yingluck won an election in 2011 and maintained relative stability until late last year. The movement against her was sparked by what she later called a political miscalculation: Thaksin’s supporters in parliament tried to ram through a bill that would clear him of graft charges and allow him to return home.

Since coming to power in 2001, Thaksin has been Thailand’s most controversial figure. He built his political clout in the long-ignored countryside, offering debt-forgiveness programs and near-free health care. But, meanwhile, he built a powerful political machine that included cronies and family members — and excluded the Bangkok aristocracy that was used to controlling the country.

Thai politics are notoriously fickle; the country has had 18 coups since a constitutional monarchy was formed in 1932. But the latest turmoil has taken a particular toll on one of Southeast Asia’s most important economies. After its latest monetary policy committee meeting, Thailand’s central bank said economic growth in the first quarter of 2014 was expected to contract “more than previously assessed” because of the “ongoing political situation,” which caused a drop in public and private spending and in tourism.

“Looking ahead, the recovery path would hinge mainly upon the political developments,” the Bank of Thailand said.