At the outbreak of the War of the Pacific, and already with the rank of captain, was commissioned to acquire weapons and a ship in the United States, a task that was interrupted, due to political swings. Back to Peru, he was named prefect of Callao and commander of the batteries during the defense of the port before the blockade of the Chilean squadron. He fought in the battles of San Juan and Miraflores, and had to order the destruction of several boats to prevent them from falling into enemy hands (January 1881).