Originally a Roman port called "Portus Divinus", Mers-el-Kébir became an Almohad naval arsenal in the 12th century, fell under the rulers of the Kingdom of Tlemcen in the 15th century, and eventually became a center of pirate activity around 1492. It was occupied variously by the Ottoman Turks, Portuguese and Spanish, with the Spanish (who named it "Mazalquivir") capturing it in 1505 under Cardinal Cisneros. Mazalquivir was the base used to capture neighbouring Oran in 1509. The Spanish held both cities until 1708, when they were driven out by Turkish Bey Mustapha Ben Youssef (also known as "Bouchelaghem"). The Spanish returned in 1732 when the armada of the Duke of Montemar was victorious in the Battle of Aïn-el-Turk and again took Oran and Mazalquivir. Both cities were held until 1792, when they were sold by King Carlos IV to the Dey of Algiers.