At this point the Amazigh embraced Islam and invaded Spain (around 711 AD) under Moussa Ibn Nusair. There is still a lot of Arab (or Moorish) architectural evidence in Spain. Around 1400 Spain got tired of being occupied by Arabs and chased them back into Morocco. Many Jews moved from Spain to Morocco at this time since the Inquisition was in full swing and not so fun for Jews (or anyone, really). There is still a large Jewish population in Morocco to this day. In 1666 the sultanate was united by the Alaouite Dynasty who have since been the ruling house of Morocco. They consolidated power and chased out the Spanish and Portuguese.
I have only been here a week and have heard at least 20 times that Morocco was the FIRST country to recognize the fledgling United States in 1777. In 1787 the U.S. ratified a formal treaty of Peace and Friendship with Morocco, which is still in effect and is our oldest, unbroken treaty relationship. (There were older ones, but we broke them). Basically the Sultan, Muhamed III, took pity on our puny country because our ships were getting trashed by the Barbary pirates. He said we would be protected in his harbors.
In 1912 France decided to "protect" Morocco, which is a nice way of saying "colonize." We turned a blind eye and Muhamed V was sent packing to exile in Madagascar (another French colony at a convenient remove). If you've seen the movie, "Casablanca," it takes place in early World War II when Morocco was governed by the Vichy French (the ultimate insult). After almost 50 years, and a lot of agitation, the Moroccans regained their independence from France, and here we are today. The current monarch is Mohamed VI, the grandson of the deposed monarch.
Moroccans, despite the fact that we ditched them in their hour of need, love Americans. There are not many Muslim countries that fall into this category. In fact Moroccans seem to like just about everyone and have even forgiven the French. I think that's what happens when your country is thousands of years old and has survived dozens of conquests. Each receding wave of vanquished conquerors has simply added another layer of cultural complexity to the country. It's like a game for them.
As evidence, here's a picture whose components span a thousand years and several cultures: