Early history Although the early human occupation of the region dates back to prehistoric times, an archaeological campaign undertaken in 1997 revealed a
Phoenician wall of section dating from the eighth century BC. Pretending that the city had been conquered by a Castilian Military Order,
Alfonso X of Castile claimed it for himself, coming to impose siege and conquer it in 1252. The following year, a treaty was signed by which
Alfonso III of Portugal (1248–1279) would marry Afonso X's daughter and, if that union resulted in a son who would turn seven, his maternal grandfather would give him the gift of the Algarve. Since the conditions of this legislation were fulfilled in 1264, Afonso X delivered the Algarve to Afonso III by letter of 20 September, set in Seville. Because of this act, the Portuguese sovereign granted
foral letters to various Algarvian villages, the first of which Tavira in August 1266. Under the reign of King Dinis (1279–1325), the castle was repaired and reinforced and the village fence expanded around the year 1292. The sovereign, by Royal Letter of 15 April 1303, extended the privileges of the residents, preventing their property from being seized or sold except for debts with the Crown.
18th century to modern day Later, in the context of the
Portuguese Restoration War,
John VI of Portugal (1640–1656) confirmed all the privileges granted to Tavira by his predecessors, determining works to modernize the medieval castle, reinforcing its structure and adapting it to the shots of the then modern artillery. The defense of the village was complemented, in 1672, by the beginning of the construction of the São João da Barra de Tavira Fortress, in Gomeira, bordering the Gilão river in 1717. In the 18th century, the castle's structure was severely damaged by the
1755 Lisbon earthquake, which certainly contributed to the fact that, in the following centuries, the defensive perimeter of the settlement was dismantled to a great extent. The Tavira Castle walls are classified as a National Monument by decree published on 16 May 1939. == Architecture ==