His military career began in 1841, when he entered the Royal Artillery College at Segovia. He became a lieutenant in 1846 and a captain in 1855. Pavía returned to Spain after fighting in the Hispano-Moroccan War (1859–60) and in the European expedition of Mexico in 1862; in the latter year he was proclaimed major.