From the 8th century onwards, the city served as the main point of contact between Morocco and Andalusia. In the 14th century the Merenids established the town as a base from which to control rebellious Rif tribes, and to attack Ceuta, but it was destroyed by Henry III of Castille in 1399. After the Reconquista (the reconquest of Spain, completed in 1492), the town was rebuilt by Andalusian refugees. It prospered, due in part to their skills, and to thriving pirate activity.
Moulay Ismail built Tetouan’s defensive walls in the 17th century, and the town’s trade links with Spain developed. In 1860, the Spanish took the town under Leopoldo O’Donnell, who extensively Europeanised it, but upon recapture, two years later, the Moors removed all signs of European influence.
At the turn of the 20th century, Spanish colonial forces occupied Tetouan for three years, claiming it was protecting Ceuta from Rif tribes. In 1913 the Spanish made Tetouan the capital of their protectorate, which was abandoned in 1956 when Morocco regained independence. Lately the Andalusian government has financed various restoration projects in the city.