A country in Africa which borders: Algeria, two cities administered by Spain, the Atlantic Ocean, a bit of the Mediterranean Sea, and and Western Sahara (which Morocco also administers, and on many maps the two are shown as one country, but Morocco's sovereignty over the area is not recognized by the UN).

The history of Morocco is complex. The tribes known collectively as Berbers (a name applied to them by Arabs) have been in the area since long before the start of recorded history. In the 12th century BC, Morocco along with most of Africa's Mediterranean coast was colonized by Phoenicians. These colonies stayed close to the sea, but there was some cultural exchange with the tribespeople inland, especially after Rome sacked Carthage, the largest Phoenician colony, in 146 BC as Carthaginians fled westward. Eventually, the Romans conquered the North African coast, with Berbers as their local rulers in the towns but little influence over the nomads outside cities. However, Latin inscriptions and numbers of Christians show that the Roman influence was long-lasting.

Very little is known about the area between the collapse of the Western Roman Empire and the expansion of the Arabs in the 7th century AD. Oqba Ben Nafi of the Umayyid dynasty in Damascus brought his army into what is now Morocco in the year 683, and by 703 Moroccan Berbers even assisted with the Arab expansion across the Strait of Gibraltar into Spain. Conversion to Islam was also widespread but not universal until a descendant of the prophet Mohammed, Idriss Ben Abdallah, who had come across North Africa fleeing the Abbasid dynasty, arrived in Morocco in 788. The Muslim Berbers proclaimed him their king, and he and his son Idriss II united many of the tribes and brought a spiritual unity to the area. Idriss II also founded the city of Fez.

A few centuries later, the Almoravides, a still-nomadic tribe from the Sanhaja group of Berbers who lived south of the more urbanized kingdom, conquered the Idrisside dynasty. Their first leader, Ibn Tachafine, founded Marrakesh in 1062 as his new capital, and the Almoravide dynasty was the Islamic controller of the majority of Spain as well. Their dynasty was followed by the Almohades who were from the Masmoda group of Berber tribes in the Atlas Mountains, and then the Beni Marin, a tribe of Zenata Berbers from the east. This last were the first to establish a civil service, to establish a "Jewish quarter" in cities where Jewish people could live unmolested, and also to attract scholars from the eastern Islamic world.

However, by the 15th century, the rulers of Morocco were weakening. The Moors were expelled from Spain, and during the reign of Ibn Wattas, the Portuguese invaded the city of Asilah and took at least 5000 people as slaves. Ibn Wattas signed a treaty with Portugal which essentially gave the Portuguese access to most of the west coast of Morocco for a colony.

In 1578 at the Battle of Three Kings, a new Moroccan dynasty called the Saadians defeated the Portuguese. The Alaouites or Alawites gained power about a century later and made Morocco a greater power. Under these monarchs, the English and French were invited to trade at the city of Essaouira, and the wild tribes of the Souss area who had not previously acknowledged the central authority were pacified. mr100percent points out that "Morocco had the first US embassy, since they were the first country to recognize the US when they declared independence."

But things were dangerous for foreigners in Morocco, since many tribes kept going their own way against royal policies, and some Barbary pirates headquartered there. Under the pretext of keeping order and protecting their own nationals, the French took over Morocco in the early 20th century, and the Spanish insisted on having some influence as well. (The Germans, interested in mineral rights, also wanted a foothold in the country and nearly started a European war trying for it in 1905.) In 1906, the 30-nation Conference of Algeciras internationalized the whole mess, making Tangier an international free port, and the whole country a French protectorate, though the local sultan retained some power until Sultan Moulay Hafid signed the Treaty of Fez in 1912, which gave his power to govern to a French Resident-General (though the Sultan retained his title and presige). The French government built the ports of Casablanca and Kenitra and added modern sections to long-established cities; it also modernized the educational and legal systems. However, there still continued to be problems with rebellious nomadic tribes.

Formal independence movements did not pop up until after World War II, when the Istiqlal Party requested a democratic constitution from both the Sultan and the French authorities. This got the Istiqlal leaders arrested by the French. In 1953, the French deported the royal family to Corsica and Madagascar, which provoked a violent response from the Moroccans. In 1956, the sultan (from France) signed a declaration of a constitutional monarchy that would move toward democracy, and the French and Spanish both granted independence to Morocco (so Tangier was no longer an international port, but part of the country).

When Hassan II succeeded his father Mohamed V in 1961, he proclaimed a new constitution, and Morocco's first elected parliament convened in 1963. Hassan kept relations with the West good and was the second Arab leader to meet with Israeli leaders. In 1975, the "Green March" took place, when 350,000 Moroccans marched south into the desert carrying green-and-red Moroccan flags to reassert Morocco's sovereignty over what was then the Spanish Sahara. The "Polisario" movement opposes Moroccan rule on behalf of the local people, Saharawis. The United Nations is now overseeing a process supposed to lead to a referendum in the area, but three attempts at referenda have failed and things have not always been peaceful; Lonely Planet notes that many areas in the disputed area are mined though there has been a cease-fire since 1991.

Mohammed VI succeeded on the death of his father in 1999. The new king studied in France and produced a doctoral thesis on the relations between the countries of the European Union and the countries of the Maghreb. The king may have a relatively Westernized outlook, but there have been anti-American demonstrations in Morocco; the U.S. Peace Corps pulled out its volunteers in April 2003. Terrorist bombings occurred in Casablanca in May 2003, though no Americans were injured; these bombings were suspected to be linked to al-Qaeda.

Sources:
http://www.mincom.gov.ma/english/generalities/history/history.html
http://www.infoplease.com/ipa/A0107800.html
http://www.cia.gov/cia/publications/factbook/geos/mo.html
http://www.focusmm.com/morocco/mo_hist1.htm
http://travel.state.gov/morocco.html
http://www.lonelyplanet.com/destinations/africa/morocco/