Martínez Campos received a military education and after 1852, he served on Spain's general staff ("Estado Mayor"). Later, he was named professor in its academy. In 1860, he was sent to Africa to take part in the Tetuán War in Morocco, and he distinguished himself in 16 actions, obtaining the Cross of San Fernando and the rank of lieutenant colonel. He also took part in the Mexican 1861 campaign against urban rebels under General Juan Prim in a joint expedition along with France and Britain.