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 last six months, Yingluck had faced numerous challenges to her rule, including street protests and a probe by an anticorruption 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.