In charge of the Ayacucho prefecture during the War of the Pacific, Cavero formed and equipped a 500-strong battalion, which he led to Lima in December 1879, to support the defense of the Peruvian capital. While serving as a lieutenant colonel, he participated in the battle of San Juan and the battle of Miraflores as an assistant to Colonel Cáceres. During this conflict Cavero received three injuries that caused the amputation of his left arm.