The municipality of El Castillo began with the construction of the Fortress of the Immaculate Conception on the southern bank of the San Juan River, approximately 6 kilometers from the present-day border with Costa Rica. This was part of a series of fortifications built along the San Juan River in order to defend against pirate attacks upon the city of Granada (which can be reached by navigating upstream from the Caribbean Sea along the San Juan River into Lake Nicaragua).
Construction of the fortress, initially named “Fortaleza de la Limpia Pura e Inmaculada Concepción” (now known as the Castillo de la Inmaculada Concepción, or Fortress of the Immaculate Conception), was begun on March 10, 1673 and completed in 1675. The chosen site was the site of the present-day village of El Castillo. Despite the construction of the fortress, buccaneer William Dampier plundered the city and set it on fire on April 8, 1685.