Castelldefels Castle (Spanish: Castillo de Castelldefels; Catalan: Castell de Fels) is a frontier fortress in the town of Castelldefels, near Barcelona in Spain, that was built to defend the frontier of the Carolingian Empire against neighbouring Muslim territories, particularly the Caliphate of Córdoba. The fortress was first recorded in the 10th century, as was the former parish church of St. Mary, contained within its outer wall.
 The castle occupies a hilltop to the northeast of the modern town centre and the castle complex includes the castle keep, a church, associated outbuildings, and a cemetery, all contained within a curtain wall. The hill was first occupied in ancient times and archaeologists have excavated remains of a Laietani settlement dating from the 3rd to the 1st century BC, and a Roman villa dating from the 1st to the 6th century AD. The castle was first recorded in AD 967, and by the 14th century a fortified house existed with a strong curtain wall. The church was also fortified in the 14th century. The castle as it stands today was largely built in the 16th century as a response to the expansion of the Ottoman Empire.
 The castle had largely fallen into ruin by the second half of the 19th century, although the church continued in use as the local parish church. In 1893 a notorious murder took place in the rectory when a young baker broke in and murdered the parish priest and his niece. The murderer was soon caught, and was executed outside the castle walls in 1895. Soon afterwards the castle was purchased by a wealthy Barcelonan banker, who refurbished it and added decorative crenellations throughout. In the early 20th century the parish church was moved to its current location and the castle church was refurbished as a family chapel. The castle again achieved notoriety during the Spanish Civil War when the International Brigades used it as a disciplinary prison camp, with resulting executions and torture.
 The castle stands upon a 59-metre (194 ft) high hill to the northeast of the town centre, occupying a prominent position overlooking the coast. The hill has a number of artificial terraces on its eastern and southern sides, and its summit is covered with vegetation.
 The castle consists of a fortress dominated by a high, circular tower. It possesses a number of smaller towers of a variety of types, and the complex includes a church, and residential buildings on the western side. The southern portion of the castle bailey is occupied by the partially fortified church and its associated outbuildings, including the rectory and vestry, and a cemetery. The castle keep, actually consisting of two main buildings, is on the west side. The eastern portion of the keep is built from red sandstone, quarried in Begues. The western portion is bulkier and has plaster-coated masonry, giving it a beige colour.
 The entire complex of buildings, incorporating both the keep and the church and their associated outbuildings, is contained within a fortified enclosure, the wall of which has been modified throughout the castle's history. The outer gate of the castle is at the northern extreme of the bailey; it is decorative in nature and was built in 1897.
 Archaeological reconnaissance of the hillside below the castle revealed abundant ancient remains, leading to the conclusion that the hill supported an ancient Iberian settlement and a later Roman villa. The Iberian settlement, inhabited by the Laietani, has been dated from the middle of the 3rd century BC to the end of the 1st century BC. The town of the Laietani covered the hilltop and the adjoining southern and eastern flanks. An Iberian water cistern was found carved from the bedrock under the castle's subsoil. A number of Iberian house remains were excavated under the church, although none have been found under the main area of the castle due to later modifications to the land surface, in order to level the courtyard in the middle of the 16th century.
 The Roman villa has been dated from the 1st century BC to the 6th century AD. The discovery of a 2nd-century funerary monument dedicated to Caius Trocina Synecdemus has led the excavator to attribute the ownership of the villa to him. The villa probably fell within the ager of Barcino, and was at the edge of a small port; it was probably used by Trocina Synecdemus to fund his public office of sevir augustalis (priest of the Imperial cult) in Barcino.
 The church of St. Mary was built on the hill in the 10th century by the monastery of Sant Cugat, which had been given instruction to develop the Castelldefels region by Sunyer, Count of Barcelona. The new church was first mentioned in a document dating to AD 967. The first mention of a castle on the hill is an indirect reference to the church of St. Mary of Castrum Felix ("Fortunate Castle" in Latin). Archaeologists have not identified any remains of this early castle, suggesting that it may have been just a tower or perishable fortification, or that it stood on the highest part of the hill, located within the present-day castle courtyard, the bedrock of which was levelled during the 16th century.
 The church structure visible today is Romanesque in style and dates from the 11th century. The Romanesque church was probably consecrated in 1106. It has a single nave with three apses, a transept, and supports a small belltower.
 By the 14th-15th centuries, regional instability led to the increased need for defences, and the church was fortified. Records from the period indicate that the hilltop had been occupied by a fortified house with a strong curtain wall. The earliest known remains of the castle date to the 14th century; a truncated circular tower to the south of the church is of this date. Also in the 14th century, the church was partially fortified, particularly the southern apse, and battlements were added.
 By the middle of the 16th century the Ottoman Empire was increasingly powerful and controlled much of the Mediterranean Sea; their alliance with Barbary pirates presented increased danger to the coastal population of Catalonia. In response, King Philip II of Spain ordered the construction of an extensive series of fortifications along the Mediterranean coast. At this time, the existing fortified house was demolished and the first phase of the castle was constructed from red sandstone. At this time the castle's basal platform and retaining walls were built. The great southwest tower was erected in 1590.
 In 1893, the castle church still served as the parish church, and the rectory was inhabited. On 26 August, a 25-year-old Aragonese baker by the name of Joaquín Figueras broke into the rectory and stabbed 60-year-old parish priest Jacint Orta Berenguer 14 times. He also attacked his ex-girlfriend, 21-year-old Rita Bosch Orta, who was the priest's niece, stabbing her 27 times and shooting her twice. He is reported to have raped her as she lay dying.
 Figueras was arrested in Barcelona on 3 September and confessed to the murders, although he denied robbing and raping Rita Bosch Orta. He was tried in Barcelona in June 1894. He was quickly found guilty and was sentenced to death. He was garroted beneath the castle walls at 9am on 19 June 1895 before an estimated crowd of eight thousand people. His corpse was displayed until 5pm; he was then buried next to his victims in the castle cemetery.
 By the second half of the 19th century, the castle had fallen into ruin and, at the end of the century, its ownership passed into the hands of Manuel Girona, a powerful Barcelonan banker and politician. He contracted Catalan architect Enric Sagnier to restore the castle walls and towers, and add Gothic-style windows and doors. Decorative crenellations were added to the great southwest tower, and to most of the castle walls. The work was completed in 1897.
 Girona died in 1903, and his son, Manuel Girona Vidal, restored the church for use as a family chapel. He also built the current parish church in Castelldefels, and the image of St. Mary was moved there from the castle in 1911.
 The castle was used as a base of operations by the Republican International Brigades from April 1938 to January 1939, being moved there from Albacete under pressure from an offensive by General Franco. The castle was first used as a Republican military training centre. On 12 April 1938, Italian commissary general Luigi Gallo announced that the castle would be used as a prison. It was then prepared as a prison camp by the Croatian commander Milan Ćopić, in order to hold brigade soldiers accused of indiscipline. The prison guards were quartered in the chapel of the Virgen de la Salud ("Virgin of Health"). As soon as the base was put into use, 265 prisoners were moved to the castle. Ćopić immediately ordered that 60 of them be shot in order to reduce the number of prisoners held; during the months that followed, torture and executions were carried out in the castle by the Republican forces.
 In 1988, ownership of the castle passed to Castelldefels municipal council. In 1989, the council launched a project to restore the church and its associated buildings, including the sacristy and rectory. At the same time an investigation of the castle complex was also undertaken.
 During the 1989 restoration project, workers uncovered a Latin inscription upon a limestone block embedded in the rectory wall. The block measured 93 by 60 by 52 centimetres (37 by 24 by 20 in), with the area of the inscription measuring 78 by 48.5 centimetres (30.7 by 19.1 in). The block possibly served as the base of a statue, and was inscribed with:
 C. TROCINAE
C. LIB.
SYNECDEMO
IIIIII VIR.
AUG.
VALERIA.HALINE
MARITO.OPTIMO
 This was interpreted as "To Caius Trocina Synecdemus, freedman of Caius, sevir augustalis, (dedicated by his wife) Valeria Haline for having been an excellent husband". The monument has been dated to the 2nd century AD. The inscription identified the block as one that had been examined and recorded in the same rectory by an 18th-century antiquarian. The excavator believes that the memorial stone was found very close to its original location, and that the Roman villa belonged to Trocina Synecdemus.
 41°17′02″N 1°58′41″E﻿ / ﻿41.284°N 1.978°E﻿ / 41.284; 1.978