Another brutal historical event occurred in the 14th Century. The Maghreb was for a long time at the crossroad of all trading routes used to carry precious metals towards the east and to Arab countries also to the north, meaning Europe. Sub-Saharan African gold transited through Maghrebian cities and villages.

From the 14th Century on caravans would use other southern communication routes bypassing the Maghreb. Having stretched its influence to the Upper Nile Valley the Mameluk dynasty, which ruled over Cairo, could reach the Atlantic through Savannah and deal directly with Sudanese suppliers of precious metals.

The Mediterranean north-south axis also lost some of its influence following the opening of new trading routes by Christians, namely the Atlantic trading routes. Around 1540 the Portuguese started to move most of the Sudanese gold toward the east coast. The role of central Maghreb as an intermediary steadily declined. The depletion of this unique source of wealth resulted in a weakening of the region and, eventually, in its fragmentation into many principalities.

In order to take advantage of the situation Spain, which was on the verge of completing the reconquest initiated in the 13th Century, prepared to conquer North Africa with the support of Francisco Ximenes de Cisneros, Cardinal and Minister under King Ferdinand.

On September 13, 1505, Spanish soldiers occupied Mers el-Kebir, then known as Bougie on January 6, 1509, followed by Tripoli on June of the same year and then Oran on May 19, 1509. After capturing the stony island facing Algiers, Penon, the Spanish army banned all port activities. The inhabitants abandoned the cities and, after being subjected to Spanish raids, the hinterland collapsed.

The presence of Turks in Algeria over many centuries (1518-1830) gave rise to endemic violence. The sheer frequency of rebellions fomented by local populations and the propagation of political assassination attest to that fact. One must also take into account the permanent state of war against Western powers (Spain, France, England, Portugal, etc.) and neighboring countries (Morocco and Tunisia).
Cheikh Salim Tumi, the King of Algiers, asked the Barbarossa brothers, Turkish pirates based on Djerba Island, to help him fight the Spanish. In May 1515 Aroudj launched an attack on Algiers‘ Penon, but the fortress withstood his assault and the adventure failed.

While waiting to repeat his offensive, Aroudj had Cheikh Salim Tumi strangled and declared himself „King of Algiers.“ On September 30, 1516, the Spanish government sent 3,000 men, under the leadership of Diego de Vera to assist the Penon. The expedition was a total failure. The Spanish defeat only enhanced Aroudj‘s popularity throughout all of central Maghreb. Other port cities called upon him to evict Spanish garrisons. Tribes of the Mitidja, Setif plains, Titteri, Ouarsenis, Dahra, and Zaccar were willing to place themselves under his leadership.

After Aroudj‘s death in 1518 his brother, Kheir ed-Dîn, based in Algiers, pledged allegiance to the Sultan of Constantinople (Istanbul). The regency of Algiers became reality. Kheir ed-Dîn was named Pasha and then Beylerbey, Emir of all Emirs. The Spanish saw the regency of Algiers as a threat to their Maghrebian interests. In 1519 the new King of Spain, Charles the Fifth, sent Hugo de Moncade, Lord Lieutenant of Sicily, to Algiers with a fleet of forty ships and five thousand men.

Spanish troops had to retreat. In 1529, he liberated the Penon.Controlling most coastal cities and some inland ones the Turks dominated Algeria for about three centuries. They managed part of the country with the support of „Maghzen tribes,“ who levied taxes on „Ra‘ais tribes,“ on their behalf. But their authority did not extend beyond those limited cities and plains. The more remote or unruly the tribes, the less effective was the centralized power.
The Turkish minority led an isolated existence, far from the hinterland, where it maintained a military presence solely for increasingly oppressive fiscal purposes. Its inability to merge with the local populations forced the militia to hang on even when the resources it provided could not offset ensuing international problems.

Trapped between local rebellions and increasingly influential European powers, the Dey‘s authority collapsed with only a small push. When in June 1830 37,000 French troops landed on Sidi Ferruch beach, west of Algiers, it easily defeated the 6,000 Ojak soldiers.
The middle class of Algiers opened the city‘s doors and the Dey retreated, leaving the conquerors enough to reimburse the costs of the expedition. Only the tribes would continue fighting. Thus another era of foreign occupation began for the Algerian people, with dreadful consequences.