T WO YEARS ago Lenín Moreno was narrowly elected as Ecuador’s president because he was the chosen successor of Rafael Correa, a left-wing populist who had governed the country for the previous decade during an oil boom. A social democrat, Mr Moreno has little by little reversed his predecessor’s policies. Whereas Mr Correa was an ally of Venezuela’s leftist dictator, Nicolás Maduro, Mr Moreno has backed Juan Guaidó, the opposition leader. He has opened trade talks with the United States. On April 11th British police arrested Julian Assange, the co-founder of WikiLeaks, at the Ecuadorean embassy in London after Mr Moreno withdrew asylum granted by Mr Correa in 2012.

Mr Correa once crowed that “because we are bad pupils of the IMF , things are going well in Ecuador.” Last month Mr Moreno seemed to complete the policy rupture when his government signed a $4.2bn loan agreement with the IMF .

This path from populism to moderation is one that Mr Maduro should have followed in Venezuela, but didn’t. Yet in a democracy it is politically hard, as Mauricio Macri has found out in Argentina and Mr Moreno is finding, too. It has fallen to him to clean up the economic mess left by Mr Correa, and that means taking unpopular measures.

Mr Correa did at least invest some of his oil windfall in roads and hospitals. But he squandered much of it. Public spending rose from 20% of GDP to 40% in his years in power. Public-sector wages almost doubled, too. White elephants multiplied. In January auditors revealed that five big projects under Mr Correa involving Petroecuador, the state oil and gas firm, featured a staggering $2.5bn of overbilling by contractors. As populists do when the going gets tough, Mr Correa borrowed. Public debt tripled in five years and the government took to spending the central bank’s reserves.

Even as he talked about overcoming his country’s dependence on oil, Mr Correa intensified it. He abandoned a rainy-day fund into which he should have put some of the windfall. After its currency collapsed in 1999, Ecuador adopted the dollar. This means that when conditions change, it cannot respond by devaluing. Mr Correa’s expansionary policies pushed up wages and inflation, making Ecuador’s non-oil exporters uncompetitive. When the oil price fell sharply in 2014, Ecuador was hit hard. The economy entered recession and the fiscal deficit climbed to 8% of GDP in 2016.

The aim of the programme agreed with the IMF is to put the public finances on a sustainable basis and improve the economy’s competitiveness. It involves an ambitious fiscal adjustment, of five points of GDP over the next three years. This may be easier than it looks because so much of Mr Correa’s spending was wasteful. The government has already cut the deficit significantly. The programme’s assumptions regarding growth and the oil price are conservative, according to Augusto de la Torre, a former head of Ecuador’s central bank.

The trickiest part will be raising taxes, such as VAT . This will require the assent of congress, where Mr Moreno must depend on conservative opposition parties for support. He may get it. Opposition leaders like Jaime Nebot, the mayor of Guayaquil, who wants to run for president in 2021, might prefer the economic pain to be out of the way before then.

Austerity is never easy. Further public-sector lay-offs, rises in regulated fuel prices and a planned reform to make labour contracts a bit more flexible may bring street protests. The government’s hopes of attracting foreign mining firms may be stymied by local protesters. Mr Moreno’s approval rating has fallen to 30%, from 69% in 2018. It makes it harder still that he is accused of having used undeclared consultancy fees when working for the UN in Geneva in 2013-16 to buy a flat in Spain. He denies wrongdoing. He accused Mr Correa of seeking to “destabilise” his government because of its investigations of past corruption.