History of Morocco

finally the Saadi dynasty would see Morocco rule most of Northwest Africa, as well as large sections of Islamic Iberia, or Al-Andalus. Following the Reconquista of the Iberian Peninsula, large numbers of Muslims and Jews were forced to flee to Morocco.
After the Saadi, the Alaouite Dynasty eventually gained control. Morocco was facing aggression from Spain and the Ottoman Empire that was sweeping westward. The Alaouites succeeded in stabilizing their position, and while the kingdom was smaller than previous ones in the region, it remained quite wealthy. In 1684, they annexed Tangier. The organization of the kingdom developed under Ismail Ibn Sharif (1672–1727), who, against the opposition of local tribes began to create a unified state. According to Elizabeth Allo Isichei, "In 1520, there was a famine in Morocco so terrible that for a long time other events were dated by it. It has been suggested that the population of Morocco fell from 5 to under 3 million between the early sixteenth and nineteenth centuries."
Morocco was the first nation to recognize the fledgling United States as an independent nation in 1777. In the beginning of the American Revolution, American merchant ships were subject to attack by the Barbary Pirates while sailing the Atlantic Ocean. On 20 December 1777, Morocco's Sultan Mohammed III declared that the American merchant ships would be under the protection of the sultanate and could thus enjoy safe passage. The Moroccan-American Treaty of Friendship stands as the U.S.'s oldest non-broken friendship treaty.
European influence
Successful Portuguese efforts to invade and control the Atlantic coast in the 15th century did not profoundly affect the Mediterranean heart of Morocco. After the Napoleonic Wars, Egypt and the North African Maghreb became increasingly ungovernable from Istanbul, the resort of pirates under local beys, and as Europe industrialized, an increasingly prized potential for