When the Thai army seized power in May 2014, it described it as a coup to end all coups.
The army had failed to do the job properly during the previous attempt, in 2006, one of the coup leaders told us in 2014. This time we will fix things so we never have to intervene again, he said.
The official script of the coup makers was that they intervened to end the crippling political turmoil which had shaken Thailand for most of the previous decade.
Less officially though, the junta had two objectives; to secure the first royal succession in 70 years, which, after the death of King Bhumibol Adulyadej in 2016, it did; and to cripple the political movement loyal to ousted former Prime Minister Thaksin Shinawatra, which had won every election since 2001.
This movement is viewed as an existential threat to the alliance of palace, military and big business that has dominated Thailand for most of its modern history.
The election taking place this Sunday in Thailand has to be understood within the context of this last objective.
The military's grip on power
Far from conceding the political playing field to civilian politicians, the military is campaigning to stay in power, and has tilted the field in its own favour.
General Prayuth Chan-ocha, the man who led the coup, and has been prime minister since then, hopes to keep his job. To that end, a new political party, calling itself Palang Pracha Rath (PPRP) - Power of the People's State - was formed last year.
It is backed by many officials who have served in the military government, and has co-opted a number of big-name local politicians from other parties. Gen Prayuth is its sole candidate for prime minister, even though parties are allowed to designate three.
The military has also drafted a much-criticised constitution, which allows a wholly appointed 250-seat senate to join the vote in parliament for the next prime minister. It has introduced a new voting system which disadvantages Thailand's biggest party, the pro-Thaksin Pheu Thai, by imposing a ceiling on the number of seats it can win.
Populists still going strong
Despite these clear advantages to the military, the election is being strongly contested.
Polls suggest voter turnout will be high. Loyalty to Pheu Thai remains strong in its north and north-eastern heartland, although it is barred from using the names or images of Thaksin or his sister Yingluck, both popular former prime ministers and lacks the rousing policies and personalities of its previous campaigns.
The Democrats, traditionally the second-largest party after Pheu Thai and its main rival, have ruled out joining a coalition headed by Gen Prayuth - although they have kept open the option of working with his party - as has the mid-sized party Bhum Jai Thai.
And an exciting new player, calling itself Future Forward and headed by a telegenic young billionaire, has joined the fray, promising sweeping reform. Future Forward is proving especially popular with younger Thais; seven million will be eligible to vote for the first time in this election.
These factors have cast a shadow over the military's ambition to hold onto power. In polls large numbers of people say they have not made up their minds; given the repressive climate under the military government, many prefer not to say. Gen Prayuth remains personally popular - people like his gruff, straightforward manner, and he has a relatively uncorrupt reputation.
But despite efforts to soften his image, with photographs distributed of the normally stern-looking strongman now smiling in pastel-coloured jackets and shirts, he has been reluctant to campaign, and his party has struggled to excite the voters. Its rallies have been low-octane and thinly-attended.
Billionaires and royals
Add to that a slow-moving economy on its watch, rising costs of living for low-income Thais, and a collapse of prices for vital rural commodities like rubber, sugar and rice, and the military government's core message is reduced largely to offering continued stability, together with a few populist promises like raising the minimum wage.
This is not enough to swing the allegiance of most Thaksin loyalists. A string of corruption scandals, and plain weariness with a regime that promised an election within a year or two of seizing power, but then repeatedly delayed, are also likely to cost the pro-military party support.
One sign of nerves in the military camp are the dubious criminal charges it continues to file against its opponents, especially the popular young leader of Future Forward, Thanatorn Juangroongruangkit.
It did, however, score a notable tactical victory over the pro-Thaksin camp when one of its parties, Thai Raksa Chart, was dissolved by the constitutional court over the nomination of King Vajiralongkorn's older sister as its candidate for prime minister, a celebrity royal who would have given Thaksin's allies a dramatic advantage.
Without Thai Raksa Chart in the race, the pro-Thaksin camp has little chance of reaching its target of a majority of the seats in parliament.
So Thai voters are left with a range of choices.
Pheu Thai and Future Forward are presenting themselves as the pro-democracy, anti-military camp. Each is promising to curb the pervasive influence of the armed forces in civilian affairs. Palang Pracha Rath is offering a continuation of the status quo. And the other parties are trying to woo voters with policies that appeal to their pockets, like Bhum Jai Thai's undertaking to legalise marijuana as an alternative cash crop.
In many areas, voters are likely to stick to well-known local politicians, on their records of delivering benefits to their constituencies, regardless of their party affiliation - one reason the military has tried hard to win defectors from older parties.
Because the military-appointed senate helps select the new prime minister, Gen Prayuth has a huge advantage.
His party, plus any allies who join him, needs only 126 of the 500 seats in the lower house. In addition, all future administrations are bound by the constitution to adhere to the military's 20-year plan for Thailand, restricting their options for introducing crowd-pleasing policies.
The notoriously conservative constitutional court is empowered to take drastic action against any government which deviates from this policy straitjacket.
But if the anti-military parties do well - and Pheu Thai is almost certain to be the largest party by a significant margin - they will challenge the legitimacy of any government led by Gen Prayuth. The new government will also need to bring in enough coalition allies to function in the lower house; it cannot rely on the senate alone.
Everything depends on how each of the larger parties performs, and that is hard to predict. If Palang Pracha Rath does well, exceeding 80 seats, it will probably attract coalition partners quickly.
But they will bargain hard for cabinet positions, and the coalition, likely comprising several parties, could be unstable.
If Palang Pracha Rath performs worse than expected, its efforts to keep Gen Prayuth in power will be challenged more forcefully, and Thailand may experience more political turmoil.
It will take time to confirm and assess the election results. All parliamentary horse-trading will in any case cease for the king's coronation in early May. But when it resumes, many of the ingredients of Thailand's long political conflict will still be there.
Despite earlier promises of reconciliation, five years of military rule have done very little to resolve it.