BANGKOK — A Thai court acquitted two former prime ministers of abuse of power on Wednesday in a case involving the deadly dispersal of an anti-government protest in 2008.

A division of the Supreme Court acquitted Somchai Wongsawat, his deputy, Chavalit Yongchaiyudh, and two former police officials, saying they did not intend to endanger the demonstrators by quelling what had turned into a violent protest.

Hundreds of people suffered injuries during a pitched battle that developed when police tried to clear away protesters who were blocking the entrance to the Parliament complex. They wanted to stop Somchai, who was prime minister, from delivering his first policy statement.

The protesters, who became known as the “Yellowshirts” for their garb honoring the Thai king, were seeking to bring down Somchai’s government, which they believed served as a proxy for former Prime Minister Thaksin Shinawatra, who was ousted in a 2006 military coup after being accused of corruption and disrespect for the monarchy.

Two people died in the protest. At the time it appeared that many of the injuries were caused by out-of-date tear gas canisters that exploded after being fired, but the court said blame could not be definitively assigned.

Somchai is the brother-in-law of Thaksin, whose 2006 ouster triggered sometimes-violent battles for political power. Thaksin’s supporters see the various criminal cases against him and his allies as attempts to erase his influence from Thai political life.

The defendants were accused of exceeding their authority in allowing police to use force against the protesters.

The court, the Supreme Court’s Criminal Division for Political Office Holders, said the defendants “could not have anticipated that tear gas would cause danger to protesters” and had not intended for police to attack protesters in a manner leading to death.

Somchai thanked the court after its verdict and said he was grateful there was still justice in the country. Chavalit, another former prime minister, did not comment. They could have faced up to 10 years in prison if they had been convicted.

The ruling, however, angered a small group of protesters outside the court, some of them participants in the October 2008 protest.

One woman shouted “Let them all get terrible diseases that can’t be cured and die painful deaths!” as Somchai walked away.

Somchai was one of two pro-Thaksin prime ministers forced out of office in 2008 by court decisions aided by the pressure of Yellowshirt protests. Protesters occupied the prime minister’s offices for three months and Bangkok’s two airports for about two weeks.

Thaksin’s sister, Yingluck Shinawatra, was elected prime minister in 2011 and also was forced to step down in 2014 by a controversial court ruling supported by street protests against her. The army shortly afterward ousted her government and remains in power today.

In a separate trial, Yingluck declared her innocence on Tuesday and asked for “kindness” from the court that will decide whether she mishandled a rice subsidy program that allegedly lost billions of dollars. Her bank account has been frozen after an administrative court held her responsible for some of the losses. The verdict in Yingluck’s case is to be issued Aug. 25.

Thaksin has been in self-imposed exile since 2008 to escape a prison sentence on a conflict of interest conviction.