European enclaves in North Africa before 1830

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 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.
The arrival of the Normans in Italy led to the Christian reconquest of Sicily (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.
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.
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–1742.
From West to East: 
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.
By the time of Joao III, the Portuguese empire had expanded around the globe. In this context, retaining or perhaps expanding the possessions in Morocco held no economic attraction and seemed increasingly unsustainable in military terms. In 1541 Agadir fell to the Saadi prince Moulay Muhammad, and in the same year, Portugal also lost Safi and Azamor. In 1550, they went on to lose Ksar es-Seghir and Arcila.
In 1577 Sebastian I of Portugal was able to reconquer Arcila, though it was taken by the Saadi ruler Almanzor in 1589. However Sebastian’s disastrous crusade in Morocco cost him his life and brought an end to the age of Portuguese expansion. Indeed, it led to the extinction of the independent Portuguese state between 1580 and 1640.
In 1640 Portugal regained its independence, but Ceuta opted to remain with Spain, a situation that was officially acknowledged in the Treaty of Lisbon (1668). After this Portugal retained only three enclaves in North Africa - Tangier, Casablanca and El Jadida. Tangier was ceded to England in 1661 under the Marriage Treaty as part of the dowry of Catherine of Braganza, and Casablanca was abandoned after the Lisbon earthquake of 1755. Under siege by Muhammad III, El Jadida was evacuated on 10 March 1769, bringing an end to the Portuguese presence in North Africa.
From West to East: 
Spanish possessions.
Having taken Granada in 1492, the Catholic Monarchs of Spain wanted to extend the Reconquista across the Straits of Gibraltar. 
They took a number of bridgeheads on the African mainland, first Melilla (1497), then Cazaza and Mers El Kébir (1505). The between 1508 and 1510 they extended the areas under their control widely, taking in Peñón de Vélez de la Gomera (1508), and then major coastal cities – Oran (1509), Algiers (1510), Bejaia (1510) as well as Tripoli (1510) and surroundings in coastal Libya. Spain however lacked the military means to extend its area of rule further. This limited success prompted the local Muslim rulers in North Africa to encourage Oruç Reis to attack Spanish positions and stage raids on Andalucia, Valencia and Alicante. In 1516, the year King Ferdinand died, Oruç took Algiers and expelled the Spanish.
Ferdinand's successor Emperor Charles V intended to regain Algiers and end the threat of piracy posed by Oruç. Charles landed at Oran, and Oruç was killed by Spanish forces at Tlemcen in 1518. However Charles was not able to retain control of the areas he had taken, and Oruç's brother Hayreddin Barbarossa secured the protection of the Ottoman Empire by making Algiers its vassal.
By the time Philip II of Spain assumed the throne of Portugal in 1580 as well as of Spain, all of the Spanish possessions on the North African coast had already been lost, with the exceptions of Melilla, Peñón de Vélez de la Gomera, and Oran-Mers El Kébir (Mazalquivir) while only Ceuta, Tangier, Arcila and El Jadida remained of the Portuguese territories. Although Philip III of Spain gained Larache (1610) and La Mámora (1614) in Morocco, the rise of the Alaouite dynasty meant the loss of many former possessions to Muslim rule. By the death of Moulay Ismaíl (1672–1727), the only territories remaining to Spain were Ceuta (acquired from Portugal in 1640), Melilla, the Alhucemas Islands (occupied in 1673) and Peñón de Vélez de la Gomera.
Spain's first Bourbon ruler Philip V wished to re-establish Spanish supremacy on the Algerian coast, and in 1732 sent an expedition which retook Oran and Mers El Kebir. The cities remained under Spanish rule until they were all but destroyed by an earthquake in 1790. The Spanish evacuated it in early 1792 and it came under Ottoman rule once again.
From West to East: 
French possessions.
The Franco-Ottoman alliance of 1536 set the scene for the earliest French possessions on the North African coast. In 1550 the Dey of Algiers, Turgut Reis, granted the right to fish coral on the Massacares coast, near Annaba, to Tomasino Lenche (c.1510–1568), a merchant of Marseilles. The following year, Henri II of France granted him an identical monopoly (renewed in 1560 by Charles IX). Sultan Selim II granted France a trading concession over the ports of Malfacarel, la Calla (El Kala), Collo, Cap Rose (Cap Rosa) and Bone (Annaba). In 1552 Lenche was given permission to build the first permanent French presence on the coast, the fortress known as the 'Bastion de France'.
Tomasino Lenche completed the building of the Bastion de France in 1560 and founded the Magnificent Coral Company ("la Magnifique Compagnie du Corail") for the commercial exploitation of the coast's resources. From this base, it was not long before Tomasino had diversified into selling artillery, powder and other weapons to the Dey. The wealth of the Lenches attracted the envy of Algiers however, which seized the Bastion in 1564. Lenche was able to re-establish himself there after a period, but in June 1604, the Bastion de France was torn down by soldiers from Annaba supported by galleys from Algiers sent by raïs Mourad. The fortress was eventually returned to the Lenches after diplomatic intervention by Henry IV of France. Another Algerian attack was staged in 1615, but the following year captain Jacques Vinciguerra reasserted Lenche control. Eventually, in 1619, Tomaso II Lenche sold his rights to the bastion to Charles, Duke of Guise.
After nearly a decade, on 19 September 1628, , heir to the Lenche fortunes, signed a commercial treaty with Algiers and revived the trading posts at Annaba, La Calle and the Bastion de France. As well as harvesting coral, he also opened a trading post dealing in wheat at Cap Rosa. In 1631 Louis XIII named Napollon governor of the Bastion, making it thereafter a property of the crown rather than of the Duke of Guise. However Napollon was killed during a Genoese attack in 1633, and in 1637 an Algerian fleet under Ali Bitchin seized and destroyed all the French and trading posts along the coast.
In 1664, Louis XIV mounted an expedition (known as the Djidjelli expedition) to take the city of Jijel and use it as a base against piracy. The city was taken, but after holding it for just three months, the French retreated, abandoning it. In 1682 and again in 1683 Admiral Duquesne bombarded Algiers as part of France's campaigns against piracy, and in 1684 the Dey of Algiers signed a new treaty with de Tourville. French possession of the Bastion de France was confirmed for 100 years, and previous rights in La Calle, Cap Rose, Annaba, and Bejaia were restored.
The 1684 treaty also transferred these rights from Napollon to M. Denis Dussault, before, under another treaty signed in 1690, all rights in these concessions were assigned to the French Africa Company. The French Africa Company promptly abandoned the Bastion and based its trade in la Calle, where it continued to operate until it was wound up in 1799. In 1807 the Dey of Algiers ceded all former French rights for trading posts and bases to the United Kingdom, and they were not restored to France until the Congress of Vienna. During the diplomatic crisis of 1827 between Algiers and France, the French abandoned la Calle, and the Algerians promptly destroyed it. These events were the prelude to the French conquest of Algeria in 1830.
English possessions.
Tangier (1661–1684) was ceded to England by Portugal as part of the dowry for Catherine of Braganza when she married Charles II of England. However the enclave was expensive to defend and fortify against the attacks by Moulay Ismail, and offered neither commercial nor military advantage to England. In February 1684 the English troops were transported home, the walls were torn down, and the mole in the harbour destroyed.
European possessions after 1830.
In 1830 France invaded and conquered Algeria, and in 1881, made Tunisia a protectorate. By these dates there were no longer any European coastal enclaves in either territory.
In 1859, responding to an attack on Ceuta by local tribes, Spain embarked on the Hispano-Moroccan War (1859–60). Under the 1860 Treaty of Wad-Ras Morocco recognised Spanish sovereignty in perpetuity over Ceuta and Melilla. Tetuan was ceded temporarily to Spain until Morocco's war indemnity was paid off (it was returned in 1862). In addition, Morocco ceded the territory of the old, short-lived Spanish colony of Santa Cruz de la Mar Pequeña, which was to become the Spanish territory of Ifni. At the Berlin Conference in 1884, Spain secured international recognition of a protectorate over the territory around the town of Sidi Ifni. During the Ifni War of 1957, Moroccan insurgents took control of the territory around Sidi Ifni, but not the town itself. The entire territory was eventually ceded by Spain to Morocco in 1969 following the passage of UN General Assembly resolution 2072.
From 1900, France and Spain had agreed on spheres of influence in Morocco, and in 1912 they established protectorates in their respective zones. However, the United Kingdom was not content to allow the strategically important town of Tangier to be entirely in French or Spanish hands. As a result, an international convention of 1923 established the Tangier International Zone. This was a novel hybrid in terms of sovereignty and administration. Nominally the Sultan of Morocco retained sovereignty over the territory as well as jurisdiction over its Moroccan inhabitants, while the administration was run jointly by Belgium, France, Britain, Italy, the Netherlands, Portugal, and Spain. The International Zone was abolished in 1956 at the same time as the French and Spanish protectorates when Morocco regained its independence.
Since 1956 the only European enclaves in North Africa have been Ceuta, Melilla and the plazas de soberanía.
Spanish outposts acquired after 1830: 