At the age of fourteen he joined the Spanish Army as a soldier during the War of the Second Coalition and quickly distinguished himself and four years later he joined the "Guardia de Corps". He fought well during the Spanish War of Independence, reaching the level of colonel by 1814. The following year he was assigned to the military expedition to South America led by Pablo Morillo, and participated in the Spanish reconquest of New Granada.