According to historians Henri Basset and Robert Ricard, Safi was not a very ancient city. It was mentioned in the writings of
al-Bakri in the 11th century and of
al-Idrisi in the 12th century. Al-Idrisi mentions Safi as a busy port in the 12th century. Safi was part of the
Barghawata state, a confederation of
Berber tribes with a distinct religious and political structure. This influential group in the region, resisted multiple invasions before eventually succumbing first to the
Almoravids and then being definitively eliminated by the
Almohads by 1149. The city was under
Portuguese rule from 1488 to 1541; it is believed that they abandoned it to the
Saadians (who were at war with them), since the city proved difficult to defend from land attacks. The
Sea Castle and
Kechla, two Portuguese fortresses built to protect the city, are still there today. After 1541, the city played a major role in
Morocco as one of the safest and biggest
seaports in the country. Many ambassadors to the
Saadian and
Alaouite kings during the 16th–18th centuries came to Morocco via Safi; its proximity to Marrakesh, then capital of Morocco, helped expand the maritime trade in the city.
Louis De Chénier, consul of the French court in Morocco in 1767, reported that the city was the only usable seaport at the time. A
French Navy captive,
Bidé de Maurville, who wrote the account of his stay in
Morocco in his 1765 book ''Relations de l'affaire de Larache'', reported the presence of an important number of foreign trading houses in the city: Dutch, Danish, British and French. After the Sultan
Mohammed ben Abdallah built the city of Mogador (modern-day
Essaouira), he banned foreign trade in all Moroccan ports except in his newly built city. Consequently, Safi stopped playing a leading role in the Moroccan trade. Safi's patron saint is
Abu Mohammed Salih. In 1942 as part of
Operation Torch, American forces attacked Safi in
Operation Blackstone. During November 8-10, 1942 the Americans took control over Safi and its port and took relatively few casualties compared to the other operations at
Casablanca and at
Port Mehdia. The
OCP Group, a cornerstone of Morocco's phosphate industry, established its Safi chemical complex in 1965. This site, one of the earliest in OCP’s expansion into chemical processing, significantly contributes to the local economy by processing phosphate rock sourced from
Benguerir. Equipped with facilities for fertilizer production, phosphoric acid manufacturing, phosphate washing, and a
sulfuric acid plant, the Safi complex is a major industrial hub. In 2016, it achieved record production levels, producing 1.5 million tonnes of phosphoric acid and 832,600 tonnes of triple superphosphate
TSP fertilizer., catering to both domestic and international markets. Founded in 1920, OCP is now the world's largest fertilizer manufacturer, controlling over 70% of global phosphate reserves. It employs 23,000 people and generated $5.884 billion in 2018 revenue, emphasizing the Safi complex's significant role The company holds a 31% market share of the world phosphate product market. ==Infrastructure==