The fortress remained part of the Spanish Kingdom until 1681 when Muley Ismail Ibn Sharif, the Sultan of Morocco took the city from the Spaniards.
[1] Philip III of Spain had started a campaign against privateering that led to the raid on La Goulette of 1609 and the Cession of Larache in 1610.
[2] With most of the corsairs absent, only a few remained to defend the city, they sank two ships at the harbor to prevent the Spanish invaders from swooping in.
Spanish guns started decimating the spars and yards that blocked the entrance, and the corsairs found themselves forced to torch their ships and flee.
[3] Renamed San Miguel de Ultramar, it would remain under Spanish rule for 67 years, until 1681, when the Alawite Sultan Ismaíl of Morocco recaptured it.