He was popularly regarded as the hero of the reconquest of Buenos Aires after the first British invasion of the River Plate. As a result of his success, he was appointed as viceroy, replacing Rafael de Sobremonte. It was unprecedented for a viceroy to be replaced without the King's direct intervention. But he was confirmed in office by Charles IV of Spain.