Between 1510–1822, Morocco went through significant changes that laid the foundation for its modern nation state. Most noteworthy among these changes was a shift from the Berber dynasties that had dominated the country for almost five hundred years to governments headed by shurafā’, Arab leaders who claimed lineal descent from the Prophet Muhammad. A combination of external threats (e.g., colonization from Portugal and Spain, and the threat of Ottoman expansion) and internal developments (e.g., the rising influence of murābitūn and shurafā’ within the country), along with the perceived inability of the Berber Wattasids to meet the Portuguese challenge, contributed to this dynastic change. In the five hundred years leading up to the early 21st century, two separate sharifian dynasties have governed Morocco, and the country has vacillated between periods of strong central rule and times of unrest (fitna) and weak central government. However, since the rise of the ʿAlawi dynasty in the late 17th century, ʿAlawi supremacy has not been seriously challenged, even during extensive periods of fitna or foreign colonization. Although Morocco developed a flexible system of government that helped unify the country during this period, it still fell behind European states in terms of technology, science, economy, and military strength. A degree of intellectual and social stagnation set in, such that European visitors in the 19th century perceived Morocco to be a country stuck in its medieval past. This weakness vis-à-vis its near neighbors to the north (particularly England and France) eventually set the stage for the direct colonization of Morocco by Europeans in the early 20th century.