The medieval castle of Carcabuey was the object of incursions by Ibn Hafsun at the end of the Emirate, being dominated and demolished by the emir Add-Allah in 892. Conquered by Fernando III, it was rebuilt according to the design of other fortifications, such as those in Fuengirola or Iznájar.
From the mid-13th century, it belonged to the Order of Calatrava, until, in 1333, it was conquered by Muhammad IV of Granada and reconquered and modified shortly after by Alfonso XI. It was integrated into the Señorío de Aguilar after numerous donations.
The fortress has five towers distributed along the wall, of which two are square and three circular. Inside the walled enclosure, the keep remains well-preserved. In the upper part of the courtyard sits the eighteenth-century chapel, Ermita de Nuestra Señora del Castillo.
The castle itself has gone down in history for the battle between King Alfonso X and his rival, Sancho. According to legend, the King had ordered everyone not to leave the castle under any circumstances. His rival knew that, in order to emerge victorious over the local population, he needed to flush the army out onto open ground. He learned that the Governor's daughter had a 'secret' lover and therefore devised a plan to lure her away from the castle to meet her true love and escape together. He was sure that the Governor would call out the troops to go after the girl and return her. The Governor, Pero Nuño Tello, was committed to total loyalty to his King and refused to send out the troops, thus losing his daughter forever as she fled with her lover. Interestingly, when Sancho later became King, he was sorry for the injury he had caused to the Governor and called Pero to his court to make amends. However, he was only able to meet with Pero's dead body as the Governor committed suicide, feeling that his dead body was the only loyal part of himself that he could present to the new king. His spirit, as the legend goes, would never bow to Sancho.References:
The eight towns in south-eastern Sicily, including Ragusa, were all rebuilt after 1693 on or beside towns existing at the time of the earthquake which took place in that year. They represent a considerable collective undertaking, successfully carried out at a high level of architectural and artistic achievement. Keeping within the late Baroque style of the day, they also depict distinctive innovations in town planning and urban building. Together with seven other cities in the Val di Noto, it is part of a UNESCO World Heritage Site.
In 1693 Ragusa was devastated by a huge earthquake, which killed some 5,000 inhabitants. Following this catastrophe the city was largely rebuilt, and many Baroque buildings from this time remain in the city. Most of the population moved to a new settlement in the former district of Patro, calling this new municipality 'Ragusa Superiore' (Upper Ragusa) and the ancient city 'Ragusa Inferiore' (Lower Ragusa). The two cities remained separated until 1926, when they were fused together to become a provincial capital in 1927.