He married Mercedes del Risco y Ciudad, a Peruvian woman with a reputation for such kindness that she is known to history as la santa virreina.
The situation was not easy for the Spanish; they feared not only the besieging force, but also the possibility of an uprising of the Indigenous within the city itself.
For his part in putting down the rebellion, in 1785 Avilés was promoted to brigadier and made governor of Callao.
He remained in Peru until 1795, when he was promoted to lieutenant general and sent back to Chile, this time as governor.
Avilés supported Licenciado Manuel de Salas in his projects of stimulating the production of linen and the foundation of the Academy of San Luis (1797).
Avilés remained as governor only until October 1796, when he was posted to Buenos Aires as viceroy of Río de la Plata.
(Manuel Arredondo y Pelegrín, president of the Audiencia of Lima had held the position on an interim basis, pending Avilés's arrival.)