After the independence of Peru was established, he returned to Buenos Aires, where he took part as commander of a body of volunteer cavalry in the war against Brazil in 1826–27. In the latter year he returned to Peru, participated in the war against Colombia, and was commander of Guayaquil in 1828.