Bangkok authorities are on alert for demonstrations after the ruling, as several protest groups had earlier said they would take to the streets if Prayut won the case.
Thailand's suspended prime minister Prayut Chan-O-Cha can resume office, the country's constitutional court has said, ruling that he has not exceeded his eight-year term limit.
"The constitutional court rules by a majority that the respondent's premiership has not reached the eight-year limit," said judge Punya Udchacon, reading Friday's ruling.
"The cabinet under the premiership of the respondent is counted from April 6, 2017."
The former army chief, who came to power in a 2014 military coup, was suspended last month while the court examined a legal challenge mounted by opposition parties who argued he had reached his term limit in power.
Bangkok authorities were on alert for demonstrations after the ruling, as several protest groups had earlier said they would take to the streets if Prayut won the case.
Under the 2017 Thai constitution, a prime minister cannot serve more than eight years in office, but Prayut's supporters and critics disagreed about when his term began.
The ruling counts Prayut's term from when the new army-scripted constitution came into force and means he can stay in office until 2025 — depending on an upcoming national poll, which must be held within months.
Following Prayut's suspension in August, his deputy Prawit Wongsuwan took over as caretaker prime minister, while Prayut continued to serve as defence minister.
The suspension had been hugely damaging to Prayut, Naresuan University political scientist Napisa Waitoolkiat said before the ruling, causing him to "lose face" in the eyes of voters.
Prayut and his Palang Pracharat Party are increasingly out of favour with voters, as an underperforming Thai economy hurts households.
A survey of 2,500 people earlier this month by the National Institute of Development Administration found that only 10.5 percent of respondents supported Prayut, who ranked a lowly fourth as a potential prime ministerial candidate.
Napisa said there could be angry reactions to the ruling going in Prayut's favour.
"I think there will be protests in the street and demonstrations in Bangkok against the ruling," Napisa said.
At least three protest groups — which came to prominence during 2020's massive pro-democracy rallies — said on Thursday they would demonstrate should Prayut carry the day.
Deputy national police spokesperson Kissana Phathanacharoen said officers would be deployed to provide security near the court and in Bangkok's shopping mall district, a popular location for previous protests.
Meanwhile, officials announced late on Thursday there would be a restricted zone around the court.