AT THE height of Sri Lanka’s parliamentary campaign, footage taken with a mobile phone went viral. It showed Mahinda Rajapaksa, an authoritarian former president running to become an MP, lunging at a member of the public, his fists clenched, before aides pulled him away. The short film suggested that Mr Rajapaksa already knew things were going badly for his group, the United People’s Freedom Alliance (UPFA).

Sure enough, his hopes of forming a government and becoming prime minister were dashed in the election on August 17th. Admittedly, he won a place for himself in parliament. But his alliance got just 95 of the 225 seats in the legislature. It fell well short of the 144 he mustered in 2010, a year after he presided as president over a resounding military defeat of the Tamil Tiger rebels, ending the country’s long and bloody civil war.

It is Mr Rajapaksa’s second big setback. To everyone’s surprise in January he lost a snap presidential election to a former colleague, Maithripala Sirisena. Now Mr Rajapaksa and several former members of his regime face prosecution for alleged corruption related to his nine-year rule.

Sri Lanka emerges from this latest election with a hung Parliament and a fiendishly complex array of allegiances (weirdly, Mr Sirisena is technically head of the UPFA). But outlines of a new government are clear. A coalition called the United National Front for Good Governance won 106 seats. It also has the backing of smaller parties that support its agenda of electoral, right-to-information and other reforms. Ranil Wickremesinghe, who leads the largest party in Parliament, the United National Party (UNP), will be sworn in again as prime minister. He has done the job since January, in a marriage of convenience with the new president, Mr Sirisena.

tumblr_inline_nsjd1zF9qn1qb1icv_540The marriage is supposed to prevail for the next five years, though the president and prime minister are from rival parties: the UNP is centre-right whereas Mr Sirisena’s Sri Lanka Freedom Party describes itself as socialist. The new cabinet will include members of both parties and various smaller ones. The prime minister will be in charge of economic policy with Mr Sirisena probably taking on the defence and environment portfolios. Given a record of co-operation in the seven months before the election, the two men should make a fist of things. They have a common foe in Mr Rajapaksa, who says he will use his time in Parliament to “safeguard the nation and the democratic system”.

Mr Rajapaksa and his loyalists might try to disrupt government business, possibly making it difficult for the coalition to deliver on promised constitutional changes, which need a two-thirds majority in Parliament. Mr Wickremesinghe talks about getting a consensus among parties and bringing an end to “divisive politics”. He also wants religious and other groups to contribute ideas and support.

Much needs to change. Public institutions became politicised under Mr Rajapaksa and will have to return to a neutral professionalism. The extensive network of patronage from which the Rajapaksa family and its friends benefited will have to be dismantled. The role of the army, which dominates civil life in minority Tamil areas in the north and east, will need to be adjusted. Foreign policy that once heavily favoured China has already begun to shift towards closer ties with India and the West.

The new government has a chance to resolve decades of ethnic strife between the Sinhalese majority and the Tamils. Both Mr Rajapaksa and a group of former Tamil Tigers running for seats had tried to inflame tensions. But Mangala Samaraweera, who will probably stay on as foreign minister, talks of a defeat for extremists on “both sides of the divide”—the former rebels did not win a single seat.

A plan to devolve more power to the provinces is likely to be discussed. The moderate Tamil National Alliance, which won 16 seats, says it will co-operate. An early test involves setting up a promised independent mechanism for investigating allegations of war crimes committed late in the civil war, which ended in 2009. Next month the UN Human Rights Council will publish the results of its own inquiry, which are expected to underscore abuses on both sides during that period. The ruling party says, not very clearly, that it will “provide a response within the country’s legal framework”.

As for the economy, voters want lower inflation and cheaper food. The new government now has a mandate for more market reforms and less state meddling. Opposition over economic policy is unlikely. Indeed it remains uncertain just who, officially, will lead the opposition. For now the only real contender is a Marxist party, with just six seats. Unless Mr Rajapaksa somehow makes a lunge for the role.