During 14th century, under the Berber dynasty Merinids, the town rose in importance as a port and in the early 15th century, became independent once again. It emerged as a safe harbour for pirates. This led to attacks by the Portuguese, who destroyed the town in 1468 AD.