The European enclaves in North Africa (technically 'semi-enclaves') were towns, fortifications and trading posts on the Mediterranean and Atlantic coasts of western North Africa (sometimes called also "Maghreb"), obtained by various European powers in the period before they had the military capacity to occupy the interior (i.e. before the French conquest of Algeria in 1830). The earliest of these were established in the 11th century CE by the Italian Kingdom of Sicily and Maritime republics; Spain and Portugal were the main European powers involved; both France and, briefly, England also had a presence. Most of these enclaves had been evacuated by the late 18th century, and today only the Spanish possessions of Ceuta, Melilla, and the Plazas de soberanía remain.

Italian and Sicilian possessions

Around the year 1000, small colonies of merchants began to appear in North Africa from the Republic of Amalfi and the Republic of Pisa. In 1133, Pisa negotiated a commercial treaty with the Almoravids, as did Genoa some five years later. As Almoravid power weakened, the Maritime Republics grew bolder and Pisa attempted to seize the Balearic Islands in 1114 In 1134, just one year after signing a commercial treaty with Bejaia, Genoa attacked the city before sending a combined fleet with Pisa to seize Annaba in 1136. The Pisans themselves raided Tabarka in 1140. These Italian initiatives were particularly focused on gaining control of the lucrative coral trade. There are records of the coastal area of Marsacares (today El Kala) being under the jurisdiction, at various times, of Pisa and later, Genoa.

European enclaves in North Africa before 1830

The arrival of the Normans in Italy led to the Christian reconquest of Sicily (1061 - 1091). Roger II of Sicily expanded his domains by taking Djerba in 1135. There followed the seizure of a number of Tunisian coastal cities, leading to the formation of a short-lived entity that is sometimes known as the Norman Kingdom of Africa.

European enclaves in North Africa before 1830

After the evacuation of Mahdia in 1160, the Normans ceased to control any places on the North African coast. In 1284 the new Aragonese ruler of Sicily, Frederick III, invaded Djerba once again and held it until 1333. It was retaken for Sicily by Manfredi Chiaramonte, who became lord of the island, and also seized the Kerkennah Islands. The Sicilian garrison abandoned the island in 1392, the year after Chiaramonte died.

European enclaves in North Africa before 1830

After this, the only Italian possessions in North Africa belonged to Genoa, which held Jijel (Algeria) as well as Tabarka (Tunisia), retaining the latter from 1540 to 1742.

From West to East: Jijel (Djidjelli) (intermittently before 1514) Mers el-Kharez (Marsacares) today El Kala (11th-12th centuries) Tabarka (Tabarca) (1540-1742) Norman Kingdom of Africa (1148–1160) Djerba (Gerba) (1135–1158, 1284–1333, 1389–1392)

Portuguese possessions

The Portuguese presence in North Africa dates from the reign of King João I who led the conquest of Ceuta in 1415. and continued until El Jadida was abandoned in 1769. The enclaves, mostly along the Atlantic coast of Morocco, were known in Portugal as "the Berber Algarve" or as "the Algarve on the other side" ('Algarve de Além').

The taking of Ceuta was recognised by Pope Martin V as a crusade. Possession of the city brought no economic benefits to Portugal however, as trade simply moved to other cities in the region. Accordingly, João's successor King Duarte tried to take Tangier as well in 1437, but was unable to do so. It was not until the reign of Duarte's son Afonso V that Portugal was able to expand its possessions in North Africa, taking Ksar es-Seghir in 1458 and Arcila in 1471. He also retook Tangier, but could not hold it. Afonso was known as o Africano (the African) because of his conquests, and he was the first Portuguese ruler to take the title 'King of Portugal and of the Algarves on this side and beyond the sea in Africa'. In 1486 his successor Joao II seized and fortified El Jadida (Mazagan) as the Portuguese continued their drive south towards Guinea. Two years later he accepted the submission of the governor of Safi.

The remaining Portuguese conquests in Morocco were secured by king Manuel I – Agadir, Essaouira and Azemmour. El Jadida was retaken after an earlier loss, and in 1508 direct rule was established over Safi. Mehdya was taken in 1515, though it was lost soon after in 1541. The old pirate base at Anfa, which the Portuguese had destroyed in 1468, before reoccupying and fortifying it in 1515, came to be known as "Casa Branca", hence, eventually, Casablanca.