Peru's Congress on Monday chose a 76-year-old former World Bank official as the country's new president, its third in a week.
Francisco Sagasti was elected as lawmakers met to try to find a way out of a political crisis, sparked by the impeachment of one popular president and the resignation of his controversial successor amid protests which killed two people.
Sagasti, a centrist, will serve as interim president until the end of July 2021, completing the mandate of Martín Vizcarra, who was impeached by Congress last Monday.
His successor, former Congress speaker Manuel Merino, resigned on Sunday after days of street protests during which two demonstrators were killed.
Congress was meeting for a second time to agree a president and Sagasti secured the minimum 60 votes required.
A first attempt by the legislature to agree on a president failed on Sunday, when leftist lawmaker Rocio Silva Santisteban, won just 42 votes.
Merino announced he was stepping down Sunday, following an ultimatum from Congress for him to quit or face censure after the police crackdown on protesters.
"I want to let the whole country know that I'm resigning," said Merino, 59, in a televised address, sparking celebrations in the capital Lima.
Merino only assumed office on Tuesday, a day after the assembly impeached predecessor Vizcarra on corruption charges. As speaker of Congress, he was next in line as the post of vice-president was vacant.
Thousands have taken to the streets in days of protests against Merino, who had launched the first, unsuccessful, impeachment proceedings against Vizcarra in September.
Elections are scheduled for April 2021 and Merino was due to leave office in July, when Vizcarra's mandate was to end.
The Congress ultimatum came after the Health Ministry said two protesters were killed on Saturday during a massive march in Lima, which was repressed by police firing shotgun pellets and tear gas.
Merino said that to avoid a "power vacuum" the 18 ministers he swore in on Thursday would temporarily remain in their posts, though almost all had resigned in the wake of Saturday's crackdown on protests.
His resignation was greeted by noisy celebrations in Lima, with demonstrators sounding horns and banging pots.
"We succeeded. Do you realise what we are capable of doing?" Peru national football team midfielder Renato Tapia wrote on social media.
Some lawmakers questioned the wisdom of removing Vizcarra in the midst of the coronavirus pandemic and a crippling recession.
The pandemic has hit Peru hard, with the politically fragile country having the world's highest per capita death rate – with nearly 35,000 fatalities – and GDP plunging over 30 percent in the second quarter.
Vizcarra, 57, welcomed his rival's resignation, having questioned the legality of his dismissal last week.
"A dictatorship has left the palace," he told reporters outside his home in Lima, adding that Merino "was breaking our democracy."
The popular former president did not rule out a return to his mandate and urged an early ruling on a constitutional challenge to his November 9 dismissal.
"It is essential that the Constitutional Court make a statement urgently and say whether what the congressmen did on the 9th is legal," said Vizcarra.
Thousands of mostly young protesters took to the streets Saturday to oppose what they called a parliamentary coup against Vizcarra.
The violent repression of the protests eroded whatever political support Merino had and the head of Congress called for his immediate resignation.
The police tactics have been criticised by the UN and rights organisations such as Amnesty International since the protests began on Tuesday.
The Inter-American Commission on Human Rights regretted the deaths of the two protesters and demanded "an immediate investigation of the facts and to establish responsibility."
Vizcarra had broad support since succeeding Pedro Pablo Kuczynski, the former Wall Street banker who was forced to resign under threat of impeachment over corruption allegations in 2018.
Congress impeached and dismissed Vizcarra on Monday over allegations he took kickbacks from developers when he was governor of the Moquegua region in 2014, charges he denies.