Agadir had been a Portuguese base since 1505. Before that, a few unsuccessful attempts to capture it had been made by the Spanish Governor of the Canary Islands, in 1500 and 1504. The first Portuguese fort was built privately in 1505 by a Portuguese countryman, and the King of Portugal officially acquired it in 1513, also enlarging it and calling it Santa Cruz do Cabo de Gue. Agadir was an important base, as it was sufficiently far south to connect to the sub-Saharan trade, mainly dealing in gold and slaves. Its role was so important that the southern Saadians under Araj initially refrained from attacking the city, between 1513 and 1525, until the capture of Marrakesh, and instead attacked the cities of Safi and Azemmour.
Siege
The conquest of Agadir was finally achieved by Saadian leader Muhammad al-Shaykh. He was able to mount the campaign as a peace had been signed with the northern Wattasids, through the 1527Treaty of Tadla. He first built a kasbahon top of a hill to observe the city and direct his troops more efficiently. The Kasbah is still visible to this day, located about 7 kilometers from the city center. He then set up a siege that lasted 6 months, until the Portuguese Governor of Agadir had to surrender. He used Western artillery, which he had obtained from European traders. The city had been poorly manned and provisioned by the Portuguese. Reinforcements were too sporadic. At one point a barrel of powder exploded which opened a gaping hole in the city's defenses. The Portuguese had also lost local support following the assassination of their allies Yahia u-Ta'fuft of Safi in 1518, and Malik ibn Mawud of Agadir in 1521.
Aftermath
After taking the city, Muhammad al-Shaykh reinforced its defences. The capture of the city was followed by the removal of the Portuguese presence in most of Morocco; the ports of Safi and Azammur were also evacuated by the Portuguese in October 1541. Ksar-el-Kebir and Asila were also evacuated in 1550, after the Saadians captured Fez, capital of Wattasid Morocco, in 1549. Only Ceuta, Tangier and Mazagan remained in Portuguese hands. This considerably reinforced Muhammed al-Shaykh's personal prestige, and opened the way to his conquest of the Moroccan throne. Under the Portuguese, Agadir had been an important trading center between Europe and Morocco, particularly for the products of Sus. Agadir later continued to develop as a trading base with Europe, receiving European cloth and wheat in exchange for gold and sugarcane. At the end of the 17th century, the harbour fell under the rule of the Tazerwalt leaders, who were opposed to the Alaouites. When the Alouites gained supremacy in the 18th century, they closed the harbour of Agadir, in favour of the harbour of Essaouira further north.