In 1510, the Spaniards had established themselves on a small island in front of Algiers, and forced the local ruler Sālim al-Tūmī to accept their presence through a treaty and pay tribute. Fortifications were built on the islet, and a garrison of 200 men was established. Sālim al-Tūmī had to go to Spain to take an oath of obedience to Ferdinand of Aragon. In 1516 however, the amir of Algiers Sālim al-Tūmī invited the corsair brothers Aruj and Khair ad-Din Barbarossa to expel the Spaniards. Aruj, with the help of Ottoman troops, came to Algiers, ordered the assassination of Sālim because Sālim was conspiring with the Spaniards against the pirates and Aruj, and seized the town. Spanish expeditions were sent to take over the city, first in 1516 under Don Diego de Vera, and then in 1519 under Don Ugo de Moncada, but both expeditions ended in failure. Khair ad-Din, succeeding Aruj after the latter was killed in a battle against the Spaniards at the Fall of Tlemcen. The capture of Algiers in 1516 had been made possible with the support of the Ottoman Sultan Selim I. This support was discontinued with Sultan Selim's death in 1520, causing Barbarossa to lose the city to a local kabyle chieftain in 1524, and to retreat to his fief of Djidjelli.
Reconquest
When Suleiman the Magnificentdeclared war on Ferdinand of Habsburg in January 1529, he also wished to goon the offensive in the western Mediterranean, and therefore chose to renew Ottoman support to Barbarossa. Barbarossa received from the Ottoman Empire 2,000 janissaries, artillery, and important financial support. Through bribery Barbarossa first obtained a change in the allegiance of the supporters of the Algiers sheikh. After taking power in the city, Barbarossa then started to lay siege to El Peñón de Argel, the Spanish fortress at the entrance of the harbour. After 22 days enduring artillery fire, the Spanish under Governor Don Martin de Vargas finally surrendered on 29 May 1529, with only 25 men left and without having received help from the Spanish mainland. Vargas was cudgelled to death, the fortress was dismantled, and the stonework used to build a seawall using Christian slaves as manpower.