History of the Regency of Algiers

History of the Regency of Algiers includes political, economic and military events in the Regency of Algiers from its founding in 1516 to the French invasion of 1830. The Regency of Algiers was a largely independent tributary state of the Ottoman Empire. Founded by the corsair brothers Aruj and Khayr ad-Din Barbarossa, it became involved in numerous armed conflicts with European powers, and was an important pirate base notorious for Barbary corsairs.

Algiers, Tunis and Tripoli were known in Europe as the Barbary States. The Ottomans called them Garb Ocakları (western garrisons). Ottoman-appointed governors initially acted as regents, but later the regents became military rulers elected by the janissary diwân council of government.

The state financed itself primarily through privateering and the slave trade. Algerian corsairs waged a holy war on the Christian powers of Europe, capturing European merchant ships and plundering coastal regions in the Mediterranean and the Atlantic as far north as Ireland and Iceland. Algiers also asserted its dominance over neighboring Maghrebi states, imposing tribute and border delimitation on Tunisian and Moroccan sovereigns.

For more than three centuries, Spanish, French, British, Dutch and later the U.S navies fought the Barbary states until in the early 19th century they were able to inflict heavy defeats. State revenues declined when poor wheat harvests, political intrigue and janissary mutinies compounded the reduced privateering booty after various treaties were signed. Attempts to make up this shortfall with higher taxes led to internal unrest; violent tribal revolts broke out, led by maraboutic orders like the Darqawiyya and Tijānīya.

France took advantage of the domestic politics to conquer Algeria in 1830, leading to French colonial rule until 1962.

Spanish expansion in the Maghreb
In Maghrebi coastal ports the Spanish Empire conquered after the fall of the Emirate of Granada in 1492, Spanish soldiers garrisoned walled and fortified defensive strongpoints they called presidios. First Melilla fell in 1497, then the Peñón de Vélez de la Gomera in 1508. On the Algerian coast, Mers El Kébir fell in 1505, followed in 1509 by Oran, the most important seaport of the time, directly linked to Tlemcen, capital of the Zayyanid Kingdom. After the Spanish conquest of Tripoli in 1510, the Hafsids in Tunis decided they did not have the means to resist and submitted to Spanish sovereignty through humiliating agreements. This gave the Spaniards control of the waystations on the trade routes that passed through Béjaïa, Algiers, Oran and Tlemcen for caravans from Tripoli, western Sudan, and Tunis in the east and Ceuta and Melilla in the west.

Control over this trade in gold and slaves fed the Spanish treasury. The Maghreb was no longer the middleman between Europe and Africa it once had been, especially for gold. The loss of this trade led to political fragmentation, economic stagnation, and a deterioration of craftsmanship. Weak centralization was exacerbated by Spain's trade monopoly and its merchant class, and also the Spanish capacity to collect taxes.

Barbarossa brothers arrive
Ottoman privateer brothers Aruj and Hayreddin, both known to Europeans as Barbarossa ("Redbeard"), were corsair chiefs, skilful politicians and warriors feared by the Christian armies of the Mediterranean. In 1512, they were famous for victories against Spanish naval vessels on the high sea and off the shores of Andalusia, and were successfully operating off the coast of Hafsid Tunisia. Scholars and notables of Bejaïa asked them for help in dislodging the Spanish. They failed however, due to Bejaïa's formidable fortifications. Aruj was wounded while trying to storm the city, and his arm had to be amputated. He realized that his forces' position in the valley of La Goulette hampered their efforts against the Spaniards and moved them to Jijel, whose inhabitants had asked him for help. Jijel was a center for trade between Africa and Italy, occupied since 1260 by the Genoese. Aruj conquered it in 1514, established a base of operations there and formalized an alliance with the Banu Abbas leaders of Lesser Kabylia. Aruj attacked Bejaïa again with a larger force in the spring of the following year, but withdrew when his ammunition ran out and the emir of Tunis refused to supply him with any more. He did however succeed in capturing hundreds of Spanish prisoners.

New masters of Algiers
Pedro Navarro and Cardinal Francisco Jiménez de Cisneros captured Bejaïa in 1510, after taking Oran in 1509. The leader of Algiers, sheikh Salim al-Thumi of the Thaaliba, recognized Catholic king Ferdinand II of Aragon as his sovereign, and made a number of pledges. He said he would pay tribute every year, release Christian prisoners, forsake piracy, and not allow the enemies of Spain from entering his harbor. To monitor the residents of Algiers and their compliance with these pledges, Pedro Navarro captured the island of Peñon, within artillery range of the city, and garrisoned 200 men in a fort there. Residents of Algiers sought to break free of the Spanish and took advantage of the excitement over the death of King Ferdinand to send a delegation to Jijel in 1516 seeking help from Aruj and his men.

Aruj set out at the head of 5,000 Kabyles and 800 Turkish arquebusiers, while Hayreddin led a naval fleet of 16 galliots. They met up at Algiers, whose population celebrated their arrival and hailed them as heroes. Hayreddin bombarded the Spanish Peñón of Algiers from sea, and Aruj took Cherchell, where he eliminated a Turkish captain who had been cooperating with Andalusians. Aruj was not immediately able to recover the Peñón, and his presence undermined al-Thumi, who eventually sought Spanish help to drive him out. Oruc assassinated al-Thumi, proclaimed himself Sultan of Algiers, and raised his banners in green, yellow, and red above the forts of the city. The Spaniards reacted in late September 1516 by sending Governor of Oran Diego de Vera to attack Algiers with 8000 troops. Aruj allowed De Vera's forces to land then moved against them, taking advantage of the bad weather that smashed the Spanish ships into the rocky coast to pursue them as they retreated, drowning and killing many, and also capturing many prisoners in a total defeat for the Spaniards, and a momentous victory for Aruj, which further expanded his influence in the Algerian heartland.

Campaign of Tlemcen: Death of Aruj
] After vanquishing his army at the Battle of Oued Djer in June 1517, Aruj killed Spanish vassal Hamid bin Abid, Prince of Ténès, seized his city, and expelled the Spaniards stationed there. He then divided his kingdom into two parts: an eastern part based in Dellys to be ruled by his brother Hayreddin, and a western part centered on the city of Algiers, to be ruled by him personally.

While Aruj was in Ténès, a delegation arrived from Tlemcen to complain about conditions there and the growing threat of the Spanish military, exacerbated by squabbling between the Zayyanid princes over the throne. had seized power in Tlemcen, expelled his nephew, and imprisoned him. Aruj appointed Hayreddin regent over Algiers and its surroundings and marched towards Tlemcen, capturing the fortress of the Banu Rashid along the way. To protect his rear he garrisoned it with a large force led by his brother Isaac. Aruj and his troops entered Tlemcen and released Abu Zayan from prison, restoring him to his throne, before progressing westward along the Moulouya River to bring the Beni Amer and tribes under his authority. Abu Zayan began to conspire against Aruj, so Aruj arrested and executed him.

Meanwhile, the deposed Abu Hammou III fled to Oran to beg his former enemies the Spaniards to help him retake his throne. The Spaniards chose to do so, capturing Banu Rashid and killing Isaac in late January 1518. Then they began a siege of Tlemcen that lasted six months. Aruj was able to resist for several months but finally locked himself inside the Mechouar palace with 500 Turks for several days to avoid the increasingly hostile populace, who eventually opened the gates for the Spanish in May 1518. Aruj attempted to flee Tlemcen, but the Spaniards pursued and killed him along with his Ottoman companions. His head was then sent to Spain, where it was paraded across its cities and those of Europe. His robes were sent to the Church of St. Jerome in Cordoba, where they were kept as trophies.

Algiers joins the Ottoman Empire
Hayreddin was proclaimed Sultan of Algiers in late 1519, but the death of his older brother left him in a difficult situation. He faced serious threats from the Spanish, the Zayyanid and the Hafsid dynasty, as well as the tribes of the central Maghreb. He increasingly felt a need for Ottoman financial and military support to maintain his prestige and his possessions around Algiers. In early 1520, a delegation of Algerian notables and ulemas led by Sinan Rais arrived in Constantinople,. They had instructions to propose to Ottoman sultan Selim I that Algiers join the Ottoman Empire, and make clear him the strategic importance of Algiers in the Western Mediterranean. Historian Nicolas Vatin points out that after an earlier reluctance from the Sublime Porte, Algiers officially became part of the Ottoman Empire under Selim I in the summer of 1520. The Sublime Porte named Hayreddin Barbarossa beylerbey lit. 'Prince of princes', and supported him with 2000 janissaries.

Because it had voluntarily joined the Ottoman Empire, Algiers was considered an estate of the empire, rather than a province. The Regency fleet's important role in Ottoman maritime wars made Algiers the spearhead of Ottoman power in the western Mediterranean.

Reconquest of Algiers
Sultan Belkadi defeated Barbarossa at the Battle of Issers in 1518 with joint Kuku-Hafsid forces, then captured Algiers in 1520 and ruled over it for five years (1520–1525). Hayreddin retreated to Jijel in 1521. Unable to rely solely on Andalusian recruits, he took advantage of the social divisions within the Maghreb to ally himself with the Kabyle people of Beni Abbas, rivals of Kuku. Thus he bolstered his ranks with local tribesmen. Hayreddin's corsairs aimed to attain supremacy in the central Maghreb using their religious zeal. They captured Collo in 1521, then Annaba and Constantine in 1523. Hayreddin crossed the mountains of Kabylia without incident to face Belkadi in Thénia, but Belkadi was killed by his own soldiers before a battle could take place. The debacle caused by this assassination cleared the road to Algiers, whose population had complained about Belkadi and opened the gates for Hayreddin in 1525.

But Algiers was still threatened by the Spaniards, who controlled the port from the Peñon. The Spanish commander, Don Martin de Vargas, rejected a demand that his garrison of 200 soldiers surrender. Hayreddin captured the Peñon on 27 May 1529. Using debris from the Peñon, Morisco stonemasons and Christian captive laborers, Hayreddin attached the islets to the shore by building a causeway 220 yd long, over 80 ft wide and 13 ft high from a stone breakwater, enlarging the harbor into a major port that became the headquarters of the Algerian corsair fleet.

Morisco rescue missions
In summer 1529 Barbarossa sent ships under Aydin Rais to help Spanish Muslim Moriscos flee the Spanish Inquisition, After he descended on the Valencian coast, captured Christians and took 200 Muslims aboard his ships, he defeated a Spanish squadron sent under Admiral Rodrigo de Portuondo at Formentera, capturing seven ships and their crews including the dead admiral's son, and freed 1000 Muslim galley slaves.

In 1531 Barbarossa successfully repelled Andrea Doria's Genoese navy from landing at Cherchell, and ferried about 70,000 refugees to the shores of Algiers. When there weren't enough ships to carry all the refugees the pirates would shuttle the refugees down the coast to a safer place, leave them with guards, and go back to rescue another shipload. In Algiers, the Morisco refugees settled in the heights of the city close to the kasbah, in the area known today as the "Tagarin". Others settled in Algerian cities to the east and west, where they built, as Leo Africanus said, "2,000 houses, and among them were those who settled in Morocco and Tunisia. The Maghreb people learned much of their craft, imitated them in their luxury, and rejoiced in them".

Hayreddin's successors (1534–1580)
Barbarossa raided the coasts of Spain and Italy, taking thousands of prisoners in Mahon and Naples. He captured Italian countess Giulia Gonzaga, but she escaped shortly afterward. The sultan called Barbarossa to the Porte in 1533 to become Kapudan Pasha (Admiral). He put Hasan Agha in charge in Algiers as his deputy and went to Constantinople. Two years later in June 1535, Charles V of Spain conquered Tunis, held by Hayreddin at the time.

In October 1541 Charles V led another expedition, this time against Algiers, seeking to end the Barbary pirates' dominance of the western Mediterranean. Just as a storm broke, Hernán Cortés joined an imperial fleet of around 500 ships led by Andrea Doria carrying 24,000 soldiers and 12,000 sailors before Algiers. Hasan Agha repelled the Maltese knights from the city on 25 October, exhausted and out of dry powder, as strengthening winds blew the Spanish ships onto the rocky shore. Under steady assault by Berber cavalry, Charles V led a difficult retreat to the remaining ships at Cap Matifou.

Sources estimate Spanish losses as low as 8,000 and up to 12,000 men. The losses included more than 150 ships and 200 cannons, which were recovered for use on the ramparts of Algiers. The slave market of Algiers filled with 4,000 prisoners. According to historian Roger Crowley: "There was a glut of slaves in Algiers, so many that 1541 was said to be the year when Christians sold at an onion a head." Hasan Agha received the title of Pasha as a reward, then sent a punitive expedition against the Kabyles of Kuku in 1542.

Successive expeditions tried to take control of the city of Mostaganem. A first expedition set out in 1543, then a second in 1547, in which Martín Alonso Fernández, Count of Alcaudete was defeated due to poor planning, a shortage of ammunition, and a lack of experience and discipline among the Spanish troops. Hasan Pasha, Hayreddin's son, endeavored to end the see-sawing of Tlemcen's allegiance between Ottomans and Spaniards by taking control of it in 1551. After that, the conquest of Algeria accelerated. In 1552, Salah Rais, with the help of the Kabyle kingdoms of Kuku and Beni Abbas, conquered Touggourt and Ouargla, making them tributaries. After leaving a permanent Ottoman garrison in Biskra, Salah Rais expelled the Portuguese from the peñon of Valez and left a garrison there.

In 1555 Salah Rais removed the Spanish from Bejaïa. Hasan Pasha vanquished Count Alcaudete's 12,000 men in Mostaganem three years later, setting in stone the Ottoman control of North Africa. This was followed by a failed attempt to take Oran in 1563, in which the independent Kabylian kingdoms had significant involvement.

The kingdom of Beni Abbas managed to maintain its independence, repelling the Ottomans in the First Battle of Kalaa of the Beni Abbès then the Battle of Oued-el-Lhâm, and lasting until early 18th century. Algiers had finally reached its 1830 borders towards the end of the 16th century.

War against the Spanish-Moroccans
The Saadi dynasty of Morocco expanded eastward, taking Tlemcen and Mostaganem and reaching the Chelif River. These incursions into western Algeria resulted in the campaign of Tlemcen in 1551, where Hassan Pasha defeated the Moroccans and solidified Ottoman control of western Algeria. This was followed by the Battle of Taza (1553) and the capture of Fez in 1554, in which Salah Rais defeated the Moroccan army, and conquered Morocco as far west as Fez, then put Ali Abu Hassun in place as ruler and vassal to the Ottoman sultan. The Saadi ruler Mohammed al-Shaykh concluded an alliance with Spain, but his armies were again removed from Tlemcen in 1557.

After the failed Ottoman Siege of Malta in 1565 and the Morisco revolt in 1568, beylerbey Uluç Ali marched on Tunis with 5300 Turks and 6000 Kabyle cavalry. Uluç Ali defeated the Hafsid sultan at Béja, and conquered Tunis with few losses. He then led the left wing of the corsair fleet in the Battle of Lepanto in 1571, and vanquished the Christian right wing of Andrea Doria and the Maltese Knights, saving what remained of the defeated Ottoman navy.

Christian forces under the victor of Lepanto John of Austria were able to retake Tunis in 1573, leaving 8,000 men in the Spanish presidio of La Goletta. But Uluç Ali reconquered Tunis in 1574. With the capture of Fez in 1576,, pasha of Algiers, put Abd al-Malik on the throne as an Ottoman vassal ruler of the Saadi Sultanate.

During the rule of Uluç Ali's former subordinate Hassan Veneziano Pasha in the late 16th century, Algerian privateering ravaged the Mediterranean, reaching as far as the Canary Islands. Algerian pirates were everywhere in the waters from Valencia and Catalonia to Naples and Sicily. Twenty-eight ships were captured near Málaga and 50 near the Gibraltar strait in a single season, and raiding Granada brought 4000 slaves to Algiers, including Spanish writer Miguel de Cervantes, whose time as a captive of Dragut inspired his novel Don Quixote.

In 1578 Hassan Veneziano's troops ventured deep into the Sahara to Tuat in response to pleas from its inhabitants for help against Saadi-allied tribes from Tafilalt. Kapudan Pasha Uluj Ali's campaign against Ahmad al-Mansur was cancelled in 1581; Al-Mansur had at first vehemently refused subordination to Ottoman sultan Murad III, but sent an embassy to the Porte and signed a treaty that protected Moroccan de facto independence in exchange for annual tribute. Nonetheless Figuig was part of Ottoman Algeria by 1584.

17th century: Golden Age of Algiers
Increasingly independent from Constantinople, 17th-century Algiers engaged in widespread privateering in what became known as the "golden age of corsairs". In raids on the Roman Mediterranean countryside, they wreaked havoc and took captives in Civitavecchia. The expulsion of the Moriscos reinforced the corso with new sailors who painfully weakened Spain, ravaging its mainland and domains in Sicily and the islands of Italy, where people were taken captive en masse.

Around 1600 they adopted the use of square-rigged sailing ships, introduced by Dutch renegade Zymen Danseker and began to rely less on Christian galley slaves. These new vessels enabled the corsairs to sail far into the Atlantic Ocean, using speed and surprise of nearly a hundred well armed square-rigged ships based in Algiers to grow powerful in the Atlantic. Exploring trade routes to India and America, the corsairs disrupted the commerce of all enemy nations. In 1619 the corsairs ravaged Madeira. Rais Mourad the younger plundered the coasts of Iceland in 1627, bringing 400 captives. The slave raid of Suðuroy took place in 1629, and in 1631, corsairs famously sacked Baltimore in Ireland, blocked the English Channel and seized vessels in the North Sea.

Algiers' port and navy grew and its population reached 100,000 to 125,000 in the 17th century, due to its pirate economy of forced exchange and paid protection for the safety of crews, cargo and ships at sea. The Maghrebi population became wealthy from selling seized ships and cargo through merchants in Genoa, Livorno, Amsterdam and Rotterdam. and from ransoms paid for the release of prisoners captured on the high seas. Homes and palaces were built with "the most precious objects and delicacies from the European and Eastern worlds".

Ottoman suzerainty weakens
In the 16th century France signed capitulation treaties with the Ottomans, formalizing the Franco-Ottoman alliance. In 1547, French trade rights and coral fishing were established in Algiers. The French trade post in eastern Algeria, known as the Bastion of France, was taken over by the French. Originally built to export coral, it engaged in wheat trade against the agreement, it was also fortified and turned into a military supply base and a center of espionage. Believing it gave too many privileges to foreigners, Algiers disapproved of Constantinople's foreign policy.

The authority of the pashas that the Sublime Porte appointed was not uncontested. By the 1570s, the corsairs started to hunt European ships without taking heed of the alliances of Constantinople, and the janissaries stationed in and paid by Algiers began to ignore the sultan and determine war strategy at their military council, known as the diwân. In clear defiance of the Ottoman treaty with France, of Algiers, backed by the galleys of Murat Rais, attacked the Bastion of France in 1604, then seized 6,000 sequins that Sultan Ahmed I had sent to French merchants to compensate for losses in the raid, under the pretext of breaching agreements regarding wheat exports, tribute payments, and violation of good faith in trading with Moors. The sultan ordered the new pasha to have Khider Pasha strangled in 1605.

The Porte renewed a treaty on 20 May 1605 that gave more privileges to France; Clause 14 of the treaty authorized the French to use force against Algiers if the treaty was broken. The French king Henry IV's envoy came to Algiers with a firman from the Porte ordering the French captives released and the Bastion rebuilt. Mohammed Koucha Pasha agreed, but the janissaries revolted, imprisoned the Pasha and tortured him to death in 1606. The diwân refused to authorize the reconstruction of the Bastion. They did agreed to release their French captives, but only on condition that Muslims detained in Marseilles also be released, a sign of how differently Algiers and Constantinople saw relations with France.

Ali Bitchin Rais
The Barbary corsair captains, also known as the raïs, were represented by the tai'fa, or community of corsair captains. The captains were led by a Kapudan Rais (Admiral and Minister of Foreign affairs). Since their privateering provided most of the Regency's revenue, they became the dominant politico-military power of early 17th century Algiers. A great influx of crewsmen allowing operations to scale up, both Moriscos expelled from Spain and European renegades who renounced their Christian faith between 1609 and 1619. Historian Jean-Baptiste Gramaye gave their numbers as: 857 Germans, 138 Hamburgers, 300 English, 130 Dutch and Flemings, 160 Danes, 250 Poles, Hungarians and Moscovites. Their skills proved valuable for the strength of the Algerian fleet.

Ali Bitchin Rais, a corsair of Italian origin, became admiral and head of the tai'fa in 1621. Immensely rich, he built a mosque and two palaces in Algiers, owned 500 slaves and married the daughter of the king of Kuku. In international treaties he styled himself "Governor and Captain general of the sea and land of Algiers".

Ali Bitchin's raids on Spanish Italy brought thousands of slaves to Algiers. In 1638 Sultan Murad IV called the corsairs up against the Republic of Venice. A storm forced their ships to shelter at Valona, but the Venetians attacked them there and destroyed part of their fleet. To their great anger, the sultan refused to compensate them for their losses, claiming they had not been in his service. Sultan Ibrahim IV, also known as "Ibrahim the Mad", wanted to arrest Ali Bitchin for refusing to join the Cretan War, but the population rose up against him. The diwân demanded that Ali Bitchin pay the janissaries their wages. So he took refuge in Kabylia for nearly a year, then returned in force to Algiers to claim the title of pasha and demand from Sultan Mehmed IV 16,000 sultanis in exchange for 16 galleys. The sultan appointed another pasha in 1645. When he arrived, Ali Bitchin suddenly died, possibly poisoned.

Coulougli revolt
Coulouglis were the offspring in Algiers of Turkish men and Algerian women. The rise in power of the Turkish janissaries in the early 17th century gradually weakened the appointed triennial Ottoman pashas. In 1596 the coulouglis provided with crucial help in suppressing the mutiny of the janissaries. This prompted the janissaries to consider excluding the coulouglis from strategic positions in the Regency.

Wealthy and connected with both the local population and Influential corsair captains, the coulouglis resented the janissaries and viewed them as strangers. These tensions led to a rebellion in 1629. According to Ottoman Algerian dignitary Hamdan Khodja:

"In around 1630, the coulouglis planned to seize power and conceived of expelling the Turks (their fathers and ancestors) who were the leaders of the government. They met at the Emperor's fort. The Turks noticed this plot and to thwart it, had a number of workers called the Mozabites dress in women's clothes. Covered with veils, carrying hidden weapons and ammunition, they presented themselves at the fort as women fleeing the tyranny of the Turks. Immediately after they entered the fort, they attacked the rebels, and were assisted by janissary reinforcements who had followed them closely. They submitted the coulouglis and ended their schemes."

The coulouglis were expelled from Algiers and their properties were seized. In 1633, the coulouglis tried to take the city of Algiers in a surprise attack, taking advantage of the unrest when Hassan Pasha defaulted on the janissary payroll to infiltrate the city with 57 men and enter the pasha's residence, Djenina Palace, hoping for support from a popular uprising. However, no uprising took place and the infiltrators were surrounded by janissaries. Without hope of relief, they blew up the powder magazine, causing a huge explosion in the kasbah, and thereby sacrificed themselves along with many janissary soldiers.

This defeat brought severe consequences for the coulouglis, as they were excluded from the diwân council and prohibited from promotion in the army. Their salaries were still paid from the state treasury for fear of further discontent, yet they were nonetheless closely watched.

When the janissaries took direct control of the Regency in what is known as the Agha period from 1659 to 1671, the first generation of coulouglis gained the right to be promoted within the Odjak. The coulouglis' efforts in the battle of Moulouya in 1693 were rewarded by Dey Hadj Chabane, who restored their rights and treated the Turks and their children on an equal footing. But coulouglis were prohibited from becoming dey.

Foreign policy
The Hapsburg Empire signed a peace treaty with the Ottoman Empire in the early 17th century, ending the Long Turkish War. Algiers refused to abide by the capitulation treaties between Europe and Constantinople, however, prompting European powers to negotiate treaties directly with Algiers on commerce, tribute payments and slave ransoms. in an acknowledgement of the autonomy of Algiers despite its formal subordination to the Sublime Porte.

Algeria's foreign relations were governed by a militant Islam that believed in the superiority of Algiers over its opponents, demanded gifts and tribute, and avoided military setbacks that might bring religious protectionism and territorial loss to European powers. This was maintained by playing the adversaries of Algiers off against each other and averting any coalition that could pose a serious threat. European nations at war with Algiers could not compete with shipping from nations at peace with it. In fact, the lucrative cabotage business between Mediterranean ports required peaceful relations with Algiers, prompting European vessels to carry passports issued by their diplomatic missions in Algiers to protect them from Algerian pirates.

Algiers could not be at peace with all European states at the same time without weakening privateering; a religious, codified and strictly controlled form of warfare engaged by Algiers, which kept revenues from naval spoils and tribute payments flowing to the treasury. In this regard, a treaty with the Dutch in 1663 led to privateering against French vessels, then a treaty with France in 1670 prompted Algiers to break off relations with England and the Dutch.

This conferred on Algerian foreign military elites an international legitimacy; Dutch jurist Hugo Grotius (1583–1645) noted that "Algiers exercised the jus ad bellum of a sovereign power through its corsairs". This also gave them internal legitimacy as champions of jihad.

Kingdom of France
France was the first European country to establish relations with Algiers. They began direct negotiations in 1617 after more than 900 ships were taken and 8000 Frenchmen enslaved, They reached an impasse however in part over two cannons Dutch corsair Simon Rais had taken with him to give to Charles, Duke of Guise when he left the Algerian navy in 1607. A treaty was signed in 1619, and another in 1628. Algerians undertook to:


 * Respect France's vessels and coast
 * Prohibit the sale of goods seized from French ships in their ports
 * Allow French traders to safely live in Algiers
 * Recognize and protect French concessions at the Bastion de France
 * Allow trade in leather and wax.

, head of the Bastion de France, was able to supply Marseille with all the wheat it needed. In 1629 however, fifteen corsairs from an Algerian ship were massacred and the rest taken prisoner, causing war to resume between Algiers and France.

Napollon's death and suspicions that the Bastion was supplying the French fleet encouraged the diwân to decide that the French establishments should be terminated. "That the first to speak of them should lose his life", it declared. In 1637, Ali Bitchin razed the French Bastion, but a tribal revolt sparked in response. In 1640, a new treaty returned to France its previous holdings in North Africa, however, and the coral concession obtained the right to take security measures against raids, in exchange for paying the pasha nearly 17,000 pounds.

France was engulfed in the Fronde by 1650, a series of civil wars, while the raïs operated off Marseilles and ravaged Corsica. But it did have to face the French Levant Fleet and the Knights of Malta, who scored a minor victory against Algerian vessels near Cherchell in 1655. Cardinal Mazarin gave the order to reconnoitre the Algerian coasts with a view to a permanent establishment. First Minister of State Jean-Baptiste Colbert sent large forces to occupy Collo in the spring of 1663, but the expedition failed. In July 1664, King Louis XIV ordered another military campaign against Jijel, which took nearly three months and also ended in defeat. France was forced to negotiate with Algiers and sign the 7 May 1666 agreement, stipulating the implementation of the 1628 treaty. Louis XIV, who sought to have the French flag respected in the Mediterranean, ordered several intense bombing campaigns against Algiers from 1682 to 1688 in what is known as the Franco-Algerian war. After fierce resistance led by Dey Hussein Mezzomorto, a conclusive peace treaty was signed.

Kingdom of England
English admiral Robert Mansell led an expedition in 1621 that sent burning fireships into the fleet moored in Algiers. It failed to take Algiers, however, and Mansell was recalled to England on 24 May 1621. James I negotiated directly with the pasha of Algiers in 1622 but more than 3000 Englishmen remained enslaved in Algiers. The Regency's corsairs crossed the English and Bristol channels and launched multiple raids on the English coasts, prompting Sir John Eliot, Vice-Admiral of Devon to say: “..whole Sea seem’d theirs”. Descents on land and kidnappings of inhabitants were more recurrent in the mid 17th century, when a barbary raid on Cornwall took place in 1654.

A fleet under Admiral Blake managed to sink several Tunisian ships, which convinced Algiers to sign a peace treaty with Lord Protector Oliver Cromwell. England introduced a series of anti-counterfeiting and mandatory "Algerian passports" on southbound merchant ships to guarantee each ship's authentic registry to Algerian pirate vessels. Fighting with a combined Anglo-Dutch force in 1670 cost Algiers several ships and 2200 sailors near Cape Spartel, and English ships burned seven other ships in Béjaïa. A regime change in Algiers ensued.

From 1674 to 1681 Algiers captured around 350 ships and 3000 to 5000 slaves. But since the French were also attacking them, they signed a peace treaty with Charles II on 10 April 1682 in which he recognised that his subjects were slaves in Algiers.

Dutch Republic
The English peace treaty with Algiers affected Dutch shipping. Merchants arriving at The Hague all said that the Dutch were losing trade to the English. From 1661 to 1664, the Dutch sent Michiel de Ruyter and Cornelis Tromp on several expeditions to Algiers in an attempt to make the Algerians accept the free ships, free goods principle. Although the Algerians had accepted the principle in 1663, they reneged a year later. De Ruyter was again dispatched to Algiers, but the beginning of hostilities with England, leading up to the Second Anglo-Dutch War, cut his mission short.

A peace agreement signed in 1679 was the result of four years of negotiations, and until 1686, precariously maintained peace for Dutch trade with southern Europe, at the price of tribute to Algiers in the form of cannons, gunpowder and naval stores, which France and England both condemned. But peace did not last. Between 1714 and 1720, 40 ships were captured, and their seamen taken captive.

After lengthy negotiations and several military expeditions, the Dutch finally achieved peace. The new Dutch consul in Algiers, Ludwig Hameken, asked for a Mediterranean pass, and agreed to pay a yearly tribute for the next century. The Anglo-Spanish War (1727–1729) distracted the British from their trade rivalries, and the Dutch managed to provide stiff competition. When the war ended however, British shipping again flourished in the Mediterranean, and Dutch trade fell off.

Maghrebi wars (1678–1756)
Algeria's relations with other Maghreb countries were troubled most of the time, for several historical reasons. Algiers considered Tunisia a dependency because Algiers had annexed it to the Ottoman Empire, which made the appointment of its pashas a prerogative of the Algerian beylerbeys. Tunis had inherited ambitions in the Constantine region from the Hafsid era, and rejected Algerian suzerainty. Algerian historian Yahya Bouaziz commented on Algerian-Moroccan relations:

Both states also supported rebellions in Algiers. In 1692 inhabitants of the capital and neighboring tribes tried to depose the Ottomans while Dey Hadj Chabane was campaigning in Morocco. They set fire to several buildings and some of the ships at anchor there.

Tunisian campaigns
Tunis adamantly refused subordination to Algeria. Beginning in 1590, the diwân of Tunisian janissaries revolted against Algiers, and the country became a vassal of Constantinople itself. A peace treaty concluded on 17 May 1628 after an Algerian victory described the borders between them.

In 1675, Murad II Bey of Tunis died. This unleashed a twenty-year civil war between his sons. Dey Chabane took this opportunity to defeat the Tunisians in the Battle of Kef, conquer Tunis and depose Mohamed Bey El Mouradi in 1694, replacing him with puppet ruler Ahmed ben Tcherkes. Hadj Chabane went back to Algiers with heavy booty, including cannons, slaves, and 120 mules loaded with gold. Tunisians revolted. Unwilling to undertake another campaign against Tunis, the janissaries mutinied, torturing and killing Hadj Chabane on 15 August 1695.

After he signed an alliance with Moulay Ismail the Sultan of Morocco, Murad III Bey of Tunis started the Maghrebi war in 1700. He took Constantine before Algiers regained the upper hand in the Battle of Jouami' al-Ulama. Ibrahim Cherif, agha of the Tunisian sipahi cavalry, put an end to the Muradid dynasty and was named dey of Tunis by the militia, the pasha and the Ottoman sultan. However, he did not manage to end the Algerian and Tripolitan incursions. Defeated near El Kef by the dey of Algiers in 1705, Ibrahim Cherif was captured and taken to Algiers. Meanwhile, Hussein I ibn Ali Bey founded the Husainid dynasty of Tunis. After a failed revolt, Abu l-Hasan Ali I Pasha took refuge in Algiers, where he gained the support of Dey Ibrahim Pasha. Kelian Hussein Bey known as Bou Kemia of Constantine sent a force of 7,000 men led by Danish slave Hark Olufs to invade Tunis in 1735, and installed bey Ali I Pasha as a vassal of Algiers who promised an annual tribute to the dey.

A campaign against Tunis in 1756 deposed Ali I Pasha and brought him to Algiers in chains. Supporters of his cousin and successor Muhammad I ar-Rashid strangled him on 22 September. Tunis became a tributary of Algiers and recognized its suzerainty for 50 years, agreeing to send enough olive oil every year to light the mosques of Algiers.

Moroccan campaigns
In 1678, Moulay Ismail mounted an expedition to Tlemcen. The tribes of Orania joined his contingents on the Upper Moulouya, and together they advanced to the Chelif to give battle there. The Ottoman Algerians brought in artillery and routed the Moroccans. Negotiations with Dey Chabane fixed the border at the Moulouya, where it remained for the rest of the Saadian period. In 1691, Moulay Ismail launched a new offensive against Orania, and Dey Chabane, supported by 10,000 janissaries and 3,000 Zwawa infantry, killed 5,000 and routed the rest of the attackers at the Moulouya before marching on Fez. Moulay Ismail surrendered. According to French historian Henri de Grammont: "He presented himself before the winner with his hands bound, and while kissing the ground three times, he said to him: You are the knife, and I the flesh that you can cut." He agreed to pay tribute and sign the treaty of Oujda confirming the Moulouya river border. In 1694, the Ottoman sultan invited that of Morocco to cease his attacks against Algiers.

In 1700, after agreeing with the Tunisian Muradids to simultaneously attack Constantine, the Moroccan sovereign launched a new expedition against Orania with an army composed mostly of Black Guards. But Moulay Ismail's 60,000 men were beaten again at the Chelif River by Dey. The dey returned to Algiers with 3000 heads and 50 Moroccan chieftains captives, then sent some of the captured horses to king Louis XIV. Moulay Ismail made one last incursion to Oran in 1707, but his army was almost entirely destroyed, which ended his projects of expansion towards Orania. In the following years, Moulay Ismaïl led Saharan incursions towards Aïn Madhi and Laghouat without succeeding in settling them permanently.

Early 18th century transformations
By the end of the 17th century, Algiers, Tunis and Tripoli had extended their rule in the hinterland, compelled by the need to supply their port cities, extensive trade with Europe and meeting the janissaries' payroll. The janissaries took the reins of power in the Barbary states at the expense of the corsairs. Their officers obtained the right from the Ottoman sultan to be appointed as pashas (representatives of the sultan), gaining uncontested legitimacy and a more peaceful system of succession.

Just like Tunisian Husayn I ibn Ali in 1705 and Tripolitan Ahmed Karamanli in 1711, Algerian Dey Baba Ali Chaouch took the Pasha title for himself in 1710. When the Habsburg monarchy concluded the peace of Passarowitz with the Ottoman Empire in 1718, Dey Ali Chaouch ignored the treaty and captured Austrian ships despite it, then refused to pay compensation to an Ottoman-Austrian delegation. This confirmed the independent foreign policy of Algiers despite its nominal subordination to the Ottoman Empire.

Algiers signed numerous treaties with European states, such as Austria in 1725, the Dutch republic in 1726, Sweden in 1729, Tuscany in 1749 and Denmark in 1751-1752, thus formalizing a period of peaceful relations with Europe as long as the dey received his tribute payments.

In 3 February 1748 Dey Mohamed Ibn Bekir issued what is known as "The Fundamental Pact of 1748" or "Pact of trust", a fundamental politico-military text that defined the rights of the subjects of Algiers and of all the inhabitants of the regency of Algiers. It also codified the behavior of the different army units: janissaries, gunners, chaoux and spahis.

Muhammad ben Othman's policy
Muhammad ben Othman Pasha became dey in 1766 as his predecessor Dey had wished. He ruled over a powerful and prosperous Algiers for a full quarter-century until he died in 1791. He was a "rational, courageous, and determined man who adhered to working according to Islamic law, loved jihad, was austere even with regard to public treasury funds", according to the memoirs of Ahmad Sharif al-Zahhar, a naqib al-ashraf of Algiers in its late Ottoman era. He successfully handled most of the problems he faced during his rule, especially Spanish and Portuguese raids. He fortified Algiers with a number of forts and towers, such as the Borj Sardinah, Borj Djedid, and Borj Ras Ammar, and repaired the next to Jenina Palace, which had been damaged by Spanish bombardment. He brought water to the city, and supplied it to all the castles, towers, fortresses, and mosques. He also built springs in the center of the city for people to drink from, and set up a special financial reserve to take care of and maintain the water supply from these streams.

As dey, Muhammad ben Othman kept the janissaries in check, developed trade, secured regular tribute payments from European states, strengthened the Algerian fleet and supplied it with men, weapons, and ships. Several captains became famous during his reign, such as Rais Hamidou, Rais Haj Suleiman, Rais Ibn Yunus and Rais Hajj Muhammad, who according to Al-Zahar commanded about 24,000 men in his various maritime incursions.

Muhammad Othman started his reign by leading campaigns against the tribes of Felissa in Kabylia, which were in constant rebellion. A first attempt in 1767 ended in failure and the tribes managed to reach the gates of Algiers itself. Nine years later however, the dey surrounded them in their mountains and made their leaders submit. Salah Bey ben Mostefa of Constantine launched several expeditions south. In 1785, he marched through the Amour Range, then stormed Aïn Beida and Aïn Madhi, and occupied all of Laghouat. He then received tribute from the Ibadi community of the south. In 1789, Salah Bey occupied the city of Touggourt, appointed Ben-Gana as "Sheikh of the Arabs" and imposed heavy tribute on the Berber Banu Djellab dynasty there.

War with Denmark
Dey Muhammad Othman Pasha increased the annual royalties paid by the Netherlands, Venice, Sweden and Denmark. They accepted, except for Denmark, which assigned Frederick Kaas to lead four ships of the line, two bomb galiots and two frigates against the city of Algiers in 1770. The bombardment ended in failure. Algerian pirates attacked Dano-Norwegian ships for a whole year afterwards. Denmark submitted to the dey's conditions and agreed to pay 2.5 million dollars in compensation for the damage to the city, and provide 44 cannons, 500 quintals of gunpowder, and 50 sails. It also agreed to ransom its captives and pay royalties every two years with various gifts to officials.

War with Spain
The War of the Spanish Succession, gave western bey Mustapha Bouchelaghem the opportunity to capture Oran and Mers-el Kebir in 1708, but he lost them back in 1732 to a successful campaign by the Duke of Montemar. In 1775 Irish-born admiral of the Spanish Empire Alejandro O'Reilly led an expedition to knock down pirate activity in the Mediterranean. The assault's spectacular failure dealt a humiliating blow to the Spanish military reorganisation.

From 1–9 August 1783 a Spanish squadron of 25 ships bombarded Algiers, but could not overcome its defenses. A Spanish squadron of four ships of the line and six frigates inflicted no significant damage on the city and had to withdraw from its guns. The commander of this fleet and that of 1784 was Spanish admiral Antonio Barceló. A European league of 130 ships from the Spanish Empire, Kingdom of Portugal, Republic of Venice and Order of Saint John of Jerusalem bombarded Algiers on 12 July 1784. This failed, and the Spanish squadron fell back from the city's defenses. Dey Mohamed ben-Osman asked for a 1,000,000 pesos to conclude a peace in 1785. Negotiations (1785–87) followed for a lasting peace between Algiers and Madrid.

After a massive earthquake in 1790, the reconquest of Oran and Mers El Kébir began. Oran was a concern for the 18th-century Spanish, torn between the competing imperatives of preserving their presidio and maintaining a fragile peace with Algiers. After the death of Mohamed ben Othman, his khaznagy (vizier) qnd adopted son Sidi Hassan was elected dey and negotiations with Count Floridablanca resumed. The resulting Spanish-Algerian Peace Treaty of 1791 ended almost 300 years of war. Mers-el-Kebir and Oran once again rejoined Algeria, and Spain undertook to "freely and voluntarily" return two cities in exchange for the exclusive right to trade certain agricultural products in Oran and Mers-el-Kébir. On 12 February 1792, Spanish soldiers left Oran and Mohammed el Kebir entered the city. Algerians had freed their land from foreign occupation.

Algerian Jewish merchants
The Jews of Algiers became an economic power and eliminated many European merchant houses from the Mediterranean, which deeply worried the Marseillais defending their threatened monopoly. French consuls resented the Jews, and urged their king to pass ordinances to prevent them from trading in French ports. But the Jewish merchants dealt in prize goods from the corsairs as well as in more usual merchandise, and were essential to the government because of their contacts and skill in aligning their affairs with the interests of the Algerian state. They were at the origin of various Algerian disputes with Spain and especially with France.

The French king established rules, port regulations, and tariffs to make good the losses of the French. These prevented Algerian merchants from trading in French ports or transporting their cargoes of wax, wheat and honey to the French market themselves. The Marseillais wanted to prohibit Algerian Jews from remaining more than three days in port, and appealed to the dey to prohibit Jews from trading in Marseilles. Muslim merchants had a cemetery in Marseilles and wanted to build a mosque there, but were refused. Moreover, the raïs, especially the Christian converts to Islam, did not dare land on Christian soil, where they risked imprisonment and torture.

Unable to own commercial vessels or to transport their goods themselves to Europe, the Algerians used foreign intermediaries and fell back again on the corso to compensate them.

Crisis of the 19th century
During Napoleon's campaign in Egypt (1798-1801), Algiers supplied the French army with large quantities of wheat. In the early 19th century, it was struck with political turmoil and economic stress. Between 1803 and 1805, famine caused by failed wheat harvests resulted in public riots that led to the death of prominent Jewish grain merchant Naphtali Busnash who was blamed for the shortages. Dey 's assassination followed, despite encouraging an anti-Jewish pogrom, which began a 20-year period of coups, in which seven deys perished.

In 1792 popular administrator of Constantine Saleh Bey was killed by order of the dey, a loss to Algiers of a seasoned politician and military and administrative leader. Once most prosperous beylik of the Regency, Constantine devolved into a period of anarchy and disorder, as 17 beys took office from 1792 to 1826, most of whom were incompetent. At the start of the 19th century, intrigues at the Moroccan court in Fez inspired the Zawiyas to stir up unrest and revolt. Muhammad ibn Al-Ahrash, a marabout from Morocco and leader of the Darqawiyyah-Shadhili religious order, led the revolt in Constantinois with his Rahmaniyya allies. The Darqawis in western Algeria joined the revolt and besieged Tlemcen, and the Tijanis also joined the revolt in the south. But the revolt was defeated by Bey Osman, and he himself was killed by Dey Hadj Ali. Morocco took possession of Figuig in 1805, then Tuat and Oujda in 1808, and Tunisia freed itself from Algeria after the wars of 1807 and 1813.

Constant war burdened the population with heavy taxes and fines that took no account of the hardship they caused and primed the population to respond to calls for disobedience, which the deys always met with brute force. This instability led to a decline in revenues, preventing the janissaries' ordinary pay from meeting their demands, which caused discontent, mutinies and military setbacks, in addition to the janissaries' usual objection to reforms that threatened their privileges. This paralyzed the government of the Regency. Destructive earthquakes, epidemics and a drought in 1814 led to the death of thousands and a further decline in trade.

Barbary Wars
Internal fiscal problems in the early 19th century led Algiers to again engage in widespread piracy against American and European shipping, taking full advantage of the Napoleonic Wars. As the most prominent Barbary state, wishing to profit and make political gains on divisions between European nations, Algiers declared war on the U.S in 1785 on the pretext of asserting its rights to search and seizure in the absence of a treaty with a given nation. It captured 11 American ships and enslaved 100 sailors. In 1797 Raïs Hamidou captured 16 Portuguese ships and 118 prisoners. The U.S. agreed to buy peace with Algiers in 1795 for $10 million including ransoms and annual tribute over 12 years. Another treaty with the Kingdom of Portugal in 1812 brought $690,337 in ransom and $500,000 in tribute. But Algiers was defeated in the Second Barbary War; U.S. admiral Stephen Decatur captured the Algerian flagship Mashouda in a battle off Cape Gata, killing Raïs Hamidou on 17 June 1815. Decatur went to Algiers and demanded war reparations from the dey and the immediate cessation of tribute to him on 29 June 1815.

A new European order had arisen from the French Revolutionary Wars and the Congress of Vienna that no longer tolerated Algerian piracy, and deemed it a "barbarous relic of a previous age". In August 1816 Lord Exmouth's naval bombardment of Algiers, ended in victory for the British and Dutch, a weakened Algerian navy, and the liberation of 1200 slaves.

After this defeat some European nations agreed to pay tribute again, and Dey Omar Agha managed to restore the defenses of Algiers,but he was eventually killed. His successor Ali Khodja suppressed insubordinate elements of the Odjak with the help of Koulougli and Zwawa soldiers. The last dey of Algiers Hussein Pasha sought to nullify the consequences of earlier Algerian defeats by restarting piracy again. He withstood a fruitless British attack on Algiers in 1824 led by Vice-Admiral Harry Burrard Neale, which cemented his false belief that Algiers could still fight off a disunited Europe.

French invasion
During the Napoleonic Wars, the merchants of Algiers sold massive amounts of wheat to France, largely bought on credit. Hussein Dey demanded in 1827 that the restored Kingdom of France pay a 31-year-old debt contracted by Napoleon in 1799 for supplies to feed the soldiers in his Napoleonic campaign in Egypt.

When Hussein Dey pressed French consul Pierre Deval about the debt at a reception, the latter's arrogant response led the Dey to slap his face with a fly-whisk. King Charles X used this incident as an excuse to break ties with Algiers and start a full-scale invasion of Algeria. The French military landed near Algiers on 14 June 1830. Algiers surrendered on 5 July, and Hussein Dey went into exile in Naples. Charles X was overthrown a few weeks later by the July Revolution and replaced by his cousin, Louis Philippe I.