Peru's congress has voted to accept President Pedro Pablo Kuczynski's resignation, paving the way for his replacement by a politician who most voters had never even heard of until recently.
By a vote of 105-12, congress granted Mr Kuczynski's request to step down after just 20 months in power, but rejected his written arguments that he was doing so as a result of his opponents' constant plotting to undermine his rule.
Congress's action cleared the way for vice president Martin Vizcarra to be sworn in.
Mr Vizcarra received something of a hero's welcome shortly after midnight when he arrived in Peru from Canada, where he had been serving as ambassador, amid one of the most politically turbulent periods in Peru's recent history.
Supporters welcomed him at the airport with a large cake in the red and white colours of Peru's flag celebrating his 55th birthday on Thursday.
A marching band was on hand and some people carried signs reading "Peru is with Vizcarra."
"With faith and optimism, Peru will always move forward," he said in brief remarks from his home.
A last-minute hitch had threatened to delay the transition of power.
Mr Kuczynski said in a tweet that the proposed language of a congressional resolution approving his resignation was "unacceptable", and if politicians pressed forward with the wording he would reverse his decision to quit, forcing congress to go forward with plans to try to impeach him.
In the end, the language was removed.
But congress nonetheless rebuked the 79-year-old, scolding him for a "political crisis that is the result of wrongful acts that the president himself has committed", according to the final text of the resolution.
Efforts to remove the unpopular Mr Kuczynski led by the daughter of former strongman Alberto Fujimori have been building for months.
But the campaign went into overdrive this week after the emergence of secretly shot videos showed allies of Mr Kuczynski, including Mr Fujimori's son, allegedly attempting to buy the support of an opposition politician to block the president's impeachment.
To stem off an even more disgraceful exit, Mr Kuczynski delivered a resignation letter to congress on Wednesday, blaming relentless attacks by his opponents for making it impossible to govern.
Mr Kuczynski's downfall was his association with Odebrecht, the Brazilian construction giant that has admitted to spreading some 800 million dollars in bribes to officials across Latin America, including 29 million dollars in Peru.
For months, even as three of his predecessors became ensnared in the bribery scandal, Mr Kuczynski vehemently denied having any business or political ties to the company.
But documents presented by Keiko Fujimori's Popular Force party showed his consulting firm had received 782,000 dollars in payments from Odebrecht a decade ago, some of them when he was a government minister.
The former Wall Street investor said he was not then managing the day-to-day affairs of his consulting business and denied any wrongdoing.
Stepping into the void left by Mr Kuczynski is Mr Vizcarra, whose name was not recognised by 81% of Peruvians in a March poll by Ipsos.
His only previous experience in public office before becoming vice president in 2016 was as governor of Peru's second-least populated province.
While Mr Vizcarra is expected to continue Mr Kuczynski's pro-business agenda, he will face a tough challenge building consensus with a hostile congress and growing public anger at Peru's political class.
Protesters scuffled with police on Thursday night while calling for new elections for both president and congress.
The new president's first test on the international stage will come in three weeks when he is expected to host US President Donald Trump and other Western Hemisphere leaders at the Summit of the Americas in Lima.