THE Parliament of Sri Lanka voted on April 28th to impose vital checks and balances on the country’s powerful presidency, ending weeks of fraught negotiations and political horse-trading. The 19th amendment to the constitution limits a president to two five-year terms, negating an earlier revision that introduced unlimited six-year terms. It also mandates that the president consult the prime minister on ministerial appointments. Among other things, it curtails any president’s immunity by making him liable to fundamental rights litigation on any official act.

This counts as a major victory for the country’s new president, Maithripala Sirisena—perhaps a necessary one. He clinched a tough presidential race in January on a pledge (one of dozens) to do away with the very office for which he was campaigning. The amendment falls well short of abolishing the presidency. But lawyers welcomed it as “a major stride for democracy”.

Critics counter that the diluted amendment is far from ideal. The government dropped clauses that would have transferred executive powers from president to prime minister (the Supreme Court had said they would require approval by referendum). The loudest challenge came from petulant loyalists of Mahinda Rajapaksa, the autocratic president whom Mr Sirisena defeated at the polls in January, who clamoured to weaken the draft even further. Some of its provisions seemed to aim at the Rajapaksa clan directly. One bans people with dual citizenship from standing for Parliament, effectively putting an end to the career of a younger brother of Mr Rajapaksa's, Gotabaya Rajapaksa, a former defence secretary who holds an American passport. Another increases the minimum age for candidates, which will put Mahinda’s eldest son out of the running for the time being.

Parliament descended into chaos during the two-day debate. The speaker suspended regular sessions at several points to allow for eleventh-hour bargaining. An especially hard sticking point regarded a council that would nominate independent commissions to oversee public-sector appointments. Finally a compromise was achieved: there will be a council, but it will consist mainly of politicians, not professionals.

In the end the amendment secured an overwhelming majority in the 225-seat assembly, with just one opposing ballot and a few absentees. The proceedings were broadcast live on state television.

Not everyone was happy. Rohan Edrisinha, a university lecturer on constitutional law, described the process as flawed. Politicians “negotiated, compromised and struck back-room deals while the country was in the dark”. Even two days later, the final amendment is not available for the public to see. And the scope for presidential immunity remains vast, sometimes comically so. Mr Sirisena's wife, for instance, will not be allowed to divorce her husband, so long as he is the sitting president.

Still the amendment places some limits on the power of Sri Lanka’s most powerful leaders and it introduces a mixed presidential and parliamentary system. This is the furthest any Sri Lankan government has gone towards pruning an overweening executive presidency in the nearly four decades since it was introduced.

The new amendment also reverses some of the damage that Mr Rajapaksa inflicted upon public institutions during his rule, from 2005 to 2015. In 2010—buoyant after having crushed the Tamil Tiger rebels—he bulldozed through an amendment of his own, the 18th, that made the executive even more robust.

By contrast, the passage of this 19th amendment was messy. After Mr Rajapaksa’s decade of authoritarian rule, it was also refreshingly democratic. The president has now promised to move speedily towards electoral reform—that is, a 20th amendment—and to follow that up with a parliamentary poll.

Calls for fresh elections will grow in coming weeks. Mr Sirisena’s minority government is built on a hastily stitched-up alliance of two main parties—his Sri Lanka Freedom Party (SLFP) and the United National Party (UNP) led by Ranil Wickremesinghe, the prime minister. He also has the support of disparate smaller parties, most of which just wanted to see the back of his predecessor.

A faction of the SLFP continues to take instructions from Mr Rajapaksa. They recently camped overnight in the Parliament chamber to protest against his being summoned to give evidence in a bribery case.

The UNP want an early election. On April 29th their treasurer said in a statement that the current Parliament lacked legitimacy and had outlived its mandate. He called for an immediate dissolution. That would be a tall order indeed.

Presidential aides say an election is more likely in August. This gives the government time to pass new electoral laws. The authorities will also deepen investigations into allegations of bribery and corruption against key members of Mr Rajapaksa’s clique. Another of his younger brothers, a former minister for economic development, is already under arrest.

Mr Sirisena’s biggest challenge is that his predecessor shows no signs of accepting defeat—or retiring gracefully. The country’s best chance at neutralising this threat is to charge ahead with progressive reform, such as the Right to Information Act, which is still in draft form.