The former head of Thailand’s military junta has been selected as the country’s next prime minister, securing the military’s already tight grip on power after the first Thai election in eight years.

Prayuth Chan-ocha, who has been PM for the past five years after a military coup in 2014, will lead a coalition government. He was voted back in on Wednesday by the newly formed democratic parliament.

Prayuth’s confirmation as prime minister came after more than 12 hours of deliberations by MPs. He was not present for the debate or the late-night vote.

Phalang Pracharat, the political party that operates as a proxy for the military, had earlier cobbled together a ruling coalition that has a slim parliamentary majority, with 254 seats in the 500-seat lower house.

Wednesday’s developments confirmed what many had feared, that an election supposed to signal Thailand’s return to democracy would lead to a continuation of military rule.

Prayuth’ previous term was defined by the jailing of critics, a ban on protests and political activity and the suppression of free speech and free media.

Most had expected the military coalition deal, in which the medium-sized Democrat and Bhumjaithai parties and 16 small entities agreed to unite with Phalang Pracharat, but it has taken weeks of backroom negotiations to secure, suggesting an uneasy and unwieldy alliance.

The Democrat party, Thailand’s oldest and most traditional party, had been particularly resistant to joining the coalition, because senior party figures feared the long-term consequences of aligning themselves with the military.

Running against Prayuth for prime minister was Thanathorn Juangroongruangkit, the head of the progressive Future Forward party. He was put forward by the Democratic Front alliance of seven parties, including Future Forward and the pro-democracy party Pheu Thai. The alliance will form a united opposition.

Pheu Thai, which is affiliated with the populist former prime minister Thaksin Shinawatra, won most seats in the election but not enough to form a majority government.

The odds were heavily weighed in favour of Prayuth’s return. According to the Thai constitution, written by the junta in 2016, the prime minister is voted for by both the elected lower house and the unelected senate, which has 250 members appointed by the junta.

Prayuth secured an easy victory with 500 votes to Thanathorn’s 244, with four abstentions.

Thanathorn’s repeated efforts to stand up to the military have cost him already. On the eve of parliament’s opening two weeks ago, Thailand’s constitutional court ruled to suspend him from his duties as an MP while it investigates him for violating election law.

If he is found guilty, he will be banned from politics completely.

The election on 24 March was dogged by allegations of irregularities, fraud and accusations that the military had manipulated the results. Future Forward MPs reported being offered up to 120 million baht (£3m) by Phalang Pracharat to switch sides and it took 45 days for the official results to be declared, which was unprecedented in Thailand.