Ecuador's ambassador to Lima, Rodrigo Riofrio, has resigned after being involved in a brawl with two women in a supermarket in the Peruvian capital.
The brawl between the ambassador and two female shoppers led to diplomatic tensions between the two neighbours.
Both countries had threatened to expel each other's ambassador, but on Monday agreed to name new people to the jobs.
Ecuador's President, Rafael Correa, said he "wouldn't let an incident in a supermarket" ruin bilateral relations.
Tensions had increased between Lima and Quito after Mr Riofrio was accused of assaulting two women, Cristina Castro and her daughter Cynthia Nunez, in a supermarket on 21 April.
Ms Castro said Mr Riofrio had become annoyed when they were served first and had insulted them.
She said her daughter had slapped the ambassador in the face in response, who in turn hit her and her daughter with a magazine.
Ms Castro said the ambassador had called them "crazy old hags" and insulted the Peruvian people.
Reports of the incident and CCTV footage from the supermarket dominated the news in Peru, with celebrities expressing their outrage at the perceived aggression.
A number of politicians called for Mr Riofrio's expulsion.
Peruvian First Lady Nadine Heredia also weighed into the discussion, saying that "aggression against women should not be tolerated".
Following a meeting with Ambassador Riofrio, Ecuadorean President Rafael Correa said he backed the diplomat, as "he had been the one to be hit first".
He also threatened "with sorrow in his heart" to bar Peru's ambassador from returning to Quito if Peru did not allow Ecuador's ambassador to return to his post.
But on Monday, the foreign ministries of Peru and Ecuador released simultaneous statements in which they declared they would each recall their ambassadors and name new candidates to the posts in an effort to safeguard their "excellent bilateral relations".
Peru said its ambassador, Javier Leon Olavarria, would "soon assume a high post" somewhere else, while Ecuador announced that Mr Riofrio would be sent to serve as ambassador in another country.
Peru and Ecuador fought a 5-week-long war in 1993 over a disputed territory on the shores of the River Cenepa, but the dispute was laid to rest with the signing of the 1998 Brasilia accord.