He fought in the British invasions of the Río de la Plata under the command of Santiago de Liniers. He returned to Spain in 1808 because of the Peninsular War, and fought at the Battle of Medina de Rioseco. He returned to the Americas with the newly appointed viceroy Baltasar Hidalgo de Cisneros, being appointed military commander of Montevideo.