Taking advantage of the total lack of defenses, a Spanish fleet commanded by Casto Méndez Núñez bombarded the city during the Chincha Islands War in 1866. Chilean merchant ships were sunk, except for those vessels whose captains hoisted foreign flags.