Capdepera was founded in 1300 and it was by royal decree that a fortress was built in which to house the residents, to protect them from pirates. This walled town became known as Capdepera Castle.
This fortified enclosure has roughly 82.5 m2 with a wall and a ditch standing on the top of a hill. In the 16th century, there were 125 houses inside its walls, but 200 years later it became a military outpost and most of the population lived outside. It was abandoned in 1856 and in 1983 it became municipal property.
Legend has it that the citizens of Capdepera hid in the castle when under siege, placing an image of Our Lady of Hope on the battlements, and the invaders were driven away by fog. The miracle is recorded inside the castle on the Capel de Nostra Senyora de la Esperança and is remembered each year at the town's annual fiesta.