Of all the Arab countries Morocco has had the least problems with Islamic terrorism. There are several reasons for this. First there is geography. Morocco is the westernmost (from Arabia) Moslem country and like the easternmost nation (Indonesia) is least affected by the Islamic radicalism that arose in Arabia in the 7th century and has survived there ever since. Then there is the ethnic factor. While Morocco is nominally an Arab country most of the people were originally Berber, the people native to North Africa for over 40,000 years. Many Moroccans are aware of their Berber ancestry and take pride in it. Berbers resisted, often successfully, the initial advance by Arab Moslem armies and while most eventually converted to Islam, they tend to wear their religion lightly and are not considered the best recruits for Islamic terrorist groups. Yet Islamic radicalism and Arab nationalism still appeals to some young Moroccans but not nearly as many as in other Arab countries. At least a thousand Moroccans are fighting with rebel groups in Syria and since September 11, 2001 thousands of local Islamic radicals have been arrested in Morocco. Most of these were freed largely because they had decided to abandon and avoid Islamic radicalism and actually did so.
The main Moroccan antidote to Islamic terrorism is an ancient monarchy that follows the moderate Malikite form of Sunni Islam. Most North Africans are nominally Malikite but outside of Morocco a greater number are tempted to sample the much more radical Wahhabism from Saudi Arabia. In Morocco the ancient monarchy was always at the center of Malikite worship. The last two kings (Hasan II 1961-99 and Mohammed VI from 1999 to the present) have encouraged democracy and good government as well as adherence to the moderate Malikite Islam. For example the current king has had over 1,600 Malikite religious teachers trained since 2006 and sent them to the 50,000 mosques throughout the country to show local clergy how to better serve their congregations and resist the temptations of Islamic radicalism. This program was in response to radical missionaries sent to Morocco by Saudi Arabia and Iran in the last decade as well as the radical propaganda spread by the Internet and Arab language satellite news channels.
Islamic terrorist groups have tried to establish themselves in Morocco since the 1990s but have found the going very difficult. There have been few Islamic terrorist attacks and those that do occur are swiftly dealt with. For example, in April 2011 a terrorist bomb went off a popular tourist café in Marrakech killing 16 people. Most of the dead were foreign tourists and it was the worst terror attack in eight years. The bomber was sloppy however and police were able to track him down along with two accomplices. What they found was a determined al Qaeda admirer who was unable to connect with al Qaeda central or travel to current terrorist hotspots (Pakistan, Afghanistan, Somalia, Yemen, Iraq, Chechnya) because the Moroccan police were monitoring anyone going to those places. But the arrested man was able to get a workable bomb design on the Internet, and was able to get bomb making materials locally. There is a lot of official al Qaeda "how to be a terrorist" stuff on the Internet, but wannabes tend to pay insufficient attention to the need for security. The incident also demonstrated that as long as there is a lot of pro-terrorist propaganda out there some small percentage (often less than one percent) of the population will buy into to it, and seek to carry out terror attacks. Since there are so few terror attacks in places like Morocco, each one that does occur is a big deal. But it's not much of a trend.
A year earlier Morocco announced it had destroyed a 24 man terrorist cell. Four of those arrested had previously been in jail for terrorist activities. This cell was not only planning attacks, but had also been active in recruiting Moroccans for terrorist groups in Afghanistan, Iraq and Somalia. Since 2003, when Islamic radicals throughout the Arab world became enraged by the American invasion of Iraq, Morocco shut down 60 Islamic terrorist cells. In early 2010 there were over a thousand Islamic radicals jailed in Morocco. Despite all this, Morocco was having a peculiar problem with Islamic radicalism. Iran sent missionaries for a while. These fanatics were armed with lots of cash and engaged in aggressive attempts to convert Moroccans to the militant brand of Shia Islam favored in Iran. This so angered Morocco that diplomatic relations with Iran were cut in 2009. Morocco also cracked down on Wahhabi missionaries from Saudi Arabia, and Islamic radicals in general. The king had an advantage in that he is a direct descendent of the Prophet Mohammed (important for any Moslem leader) and is generally popular. The Moroccan government is not as corrupt and inept as others in the Arab world, but is not a whole lot better either.
Meanwhile Morocco helps other North African and Sahel countries deal with Islamic terrorism. Morocco sends religious teachers and is always ready to discuss specific problems that Morocco had already taken care of at home. One problem Morocco has handled well is economics. Without oil Morocco has prospered by making it easy to start and operate businesses and resisted the temptation to nationalize sectors of the economy. While Morocco does not have the highest per-capita GDP in North Africa it recognized as having the best quality of life.