Media playback is unsupported on your device Media caption Yingluck Shinawatra: "We have never done anything that conveys any dishonest actions"

A Thai court has ordered Prime Minister Yingluck Shinawatra and several cabinet ministers to step down.

The Constitutional Court ruled that Ms Yingluck acted illegally when she transferred her national security head.

The ruling follows months of political deadlock. Anti-government protesters have been trying to oust Ms Yingluck since November 2013.

The remaining cabinet members have nominated the commerce minister to replace Ms Yingluck.

Analysis The judges gave a lengthy justification for their verdict, but it will inevitably be seen as political intervention by people on both sides of Thailand's divide. The government's supporters had already stated they would view the verdict as a judicial coup, and reason enough to mobilise against it. There was, predictably, jubilation in the camps of the anti-government protesters in Bangkok. But they did not get everything they wanted. The judges stopped short of holding the entire cabinet responsible for transferring the national security adviser. Only nine ministers, directly involved in approving the transfer, have been ordered to resign. So the cabinet survives, although still only in a caretaker role, until another general election can be held. The government wants that on 20 July. But the opposition Democrat party is likely to repeat its boycott, and the protesters it now allies itself to are sure to obstruct it. Nor are the government's many powerful opponents likely to give up trying to depose it. There are more legal cases pending against ministers, and the partly-appointed Senate is still sitting, and may explore other means of disabling Ms Yingluck's party. Ousting of Thai PM: Your views

"The cabinet has agreed to appoint Niwattumrong Boonsongpaisan to act as caretaker prime minister," Deputy Prime Minister Phongthep Thepkanjana said.

'Cannot stay'

Ms Yingluck had been accused of abuse of power in improperly transferring Thawil Pliensri, her national security chief appointed by the opposition-led administration, in 2011.

Appearing in court on Tuesday, she had rejected the suggestion that her party had benefited from the move.

But the court ruled against her, saying a relative had gained from the transfer.

"The prime minister's status has ended, Yingluck can no longer stay in her position acting as caretaker prime minister," a judge said in a statement.

In a press conference after the court ruling, Ms Yingluck thanked her followers for their support over the past two years, pointing out that she was democratically elected.

"We held true to the principles of honesty in running the country, and never acted corruptly, as we were accused," she told reporters.

The ruling also ousted nine cabinet members who the court said were complicit in the transfer.

An adviser to the prime minister, Nopaddon Pattama, said the court's decision was binding.

Image copyright AFP Image caption Ms Yingluck's supporters believe the courts are biased against her

Image copyright Reuters Image caption The protests are being led by Suthep Thaugsuban, a former deputy PM in an opposition-led government

"She really has no choice but to be bound by the decision because the constitution says the judgement of the court is binding on all parties, although we are going to make a political protest."

He said remaining cabinet members would continue performing their duties until a new cabinet was formed.

Earlier this month, the ruling party called a general election for July, after the snap election held in February was ruled invalid by the courts.

"We have to focus on the general election so that the Thai people can determine their own future," he said.

Media playback is unsupported on your device Media caption In 60 seconds: Thailand's crisis explained

The deputy leader of the opposition Democratic Party (PDRT), Kiat Sittheeamamorn, said the court decision would not end the political crisis.

His party maintained that political reform was needed before an election could be held, he said. "So the differences are still there and we have to see what will unfold in the next few days."

Thailand's troubles Sep 2006: Army ousts Thaksin Shinawatra

Army ousts Thaksin Shinawatra Dec 2007: Pro-Thaksin party wins election

Pro-Thaksin party wins election Aug 2008: Thaksin flees Thailand

Thaksin flees Thailand Dec 2008: Huge anti-Thaksin protests; court bans ruling party; Abhisit Vejjajiva comes to power

Huge anti-Thaksin protests; court bans ruling party; Abhisit Vejjajiva comes to power Mar-May 2010: Huge pro-Thaksin protests; more than 90 killed over 10-week period

Huge pro-Thaksin protests; more than 90 killed over 10-week period Jul 2011: Yingluck Shinawatra elected PM

Yingluck Shinawatra elected PM Nov 2013: Anti-government protests

Anti-government protests Feb 2014: Snap election held, but protesters disrupt polls; court rules polls invalid

Snap election held, but protesters disrupt polls; court rules polls invalid May 2014: PM ordered to step down Why Thailand is in political turmoil

Power struggle

The court move could trigger protests by supporters of the government, which remains very popular in rural areas.

Anti-government protests began in the Thai capital late last year, with demonstrators blockading several parts of the city.

In response, Ms Yingluck called a snap general election in February that her party was widely expected to win. But the protesters disrupted the polls and the election was later annulled.

Ms Yingluck's supporters believe that the courts are biased against her and side with the urban elite at the heart of the protest movement.

Thailand has faced a power struggle since Ms Yingluck's brother, Thaksin Shinawatra, was ousted by the military as prime minister in a 2006 coup.

Media playback is unsupported on your device Media caption Yingluck Shinawatra's adviser Noppadon Pattama: "The anti-government protesters...would like to create a political vacuum"

Mr Thaksin and his family are hated by an urban and middle-class elite who accuse them of corruption and abuse of power.

But Mr Thaksin's policies won him huge support in rural areas, and both the elections since the coup have returned Thaksin-allied governments to power.

Court rulings have in the past been a key factor amid political turbulence in Thailand.

In December 2008, a government of Mr Thaksin's allies fell from power after a court disbanded their political party for electoral fraud, allowing the opposition to form a government.