Ecuadorian president Lenin Moreno and indigenous leaders reached an agreement on Sunday to end nearly two weeks of violent protests against austerity measures adopted to obtain a multi-billion-dollar loan from the International Monetary Fund (IMF).

The demonstrations have left seven people dead and were sparked when Moreno scrapped fuel subsidies to obtain a $4.2 billion loan from the IMF, causing prices to double.

Moreno met with Jaime Vargas, the head of the indigenous umbrella grouping Conaie, for four hours of talks in the capital Quito broadcast live on state television.

“With this agreement, the mobilisations across Ecuador are terminated and we commit ourselves to restore peace in the country,” said a joint statement, adding that the government had withdrawn an order that removed fuel subsidies.

Thousands flooded into the streets of Quito shortly after the announcement, waving the national flag, honking horns and setting off fireworks in celebration.

The statement was read by an official from the UN, which mediated the talks along with the Catholic Church.

“The measures applied in all our territories are lifted,” confirmed Vargas, referring to roads and oil facilities in the Amazon blocked by protesters for almost two weeks. Those actions suspended the distribution of almost 70 per cent of the country’s crude oil.

Indigenous groups make up a quarter of Ecuador’s 17.3 million people. Thousands who had travelled from disadvantaged communities across the Amazon and the Andes to spearhead the protests in Quito started to head home after the deal was announced.

“Indigenous brothers, I have always treated you with respect and affection,” Moreno said as the talks opened. “It was never my intention to affect the poorest sectors.”

Moreno had previously declared a curfew and placed Quito under military control to quell the unrest.

On Sunday, violent clashes continued before the talks began as police fought to disperse protesters who tried to put up a barricade of debris from Saturday’s unrest.

Authorities said 1,349 people had been injured and 1,152 detained in the demonstrations.

The violence forced Moreno to relocate his government to Ecuador’s second city, Guayaquil and hit the oil industry hard with the energy ministry suspending more than two-thirds of its distribution of crude.

Conaie had previously rejected an offer of dialogue but reversed course on Saturday.

UN Secretary-General Antonio Guterres earlier called on all groups “to commit to inclusive and meaningful talks, and to work in good faith towards a peaceful solution”.

Demonstrators on Saturday ransacked and set fire to the building housing the comptroller general’s office, which was shrouded in thick smoke after being attacked with firebombs.

The prosecutor’s office said 34 people were arrested.

Protesters on Saturday also targeted a television station and a newspaper.

The Teleamazonas TV channel interrupted its regular broadcast to air images of broken windows, a burned vehicle and heavy police presence on the scene.

Nearby, protesters built barricades in front of the National Assembly building as police fired tear gas at them.

The El Comercio newspaper reported on Twitter that its offices were attacked by a “group of unknowns”.

Protesters did not immediately heed the curfew that went into effect on Saturday, with security forces struggling to impose order in some parts of the city.

“Where are the mothers and fathers of the police? Why do they let them kill us?” cried Nancy Quinyupani, an indigenous woman.

The restrictions in Quito, a city of 2.7 million, came on top of a state of emergency Moreno had declared on October 3, deploying some 75,000 military and police and imposing a night-time curfew in the vicinity of government buildings.