About the third century, Berbers began migrating from the North, pushing the native black population to the south. The Berbers gained control of important caravan trade routes between North Africa and the Sudan that passed through Mauritania. The southeast region of Mauritania was dominated successively by the kingdoms of Ghana, Mali, and Songhai. In the 11th century, Berbers founded the Muslim Almoravid dynasty, which established an empire stretching from what is now Senegal north into Spain. When Almoravid power declined in the 12th century, Arabs invaded Mauritania. By the end of the 17th century, they had won dominance over the Berbers.

Meanwhile, Portuguese explorers had reached Mauritania's coast in the 1400's. Trade in slaves and gum arabic later drew the Dutch, English, and French. Europeans did not penetrate the interior until after 1850, when French influence was extended by exploration and by military expeditions. Mauritania became a French colony in 1920 and an overseas territory in 1946.

Mauritania was made a member of the French Community in 1958. It gained full independence in 1960, and in 1966 it withdrew from the French Community. In 1976 Mauritania annexed part of Spanish Sahara but relinquished it in 1979. A border dispute in the late 1980's led to a series of violent confrontations with Senegal. In 1994, the government began a crackdown on militant Islamist organizations.

In 1992, Mauritania established a multiparty democracy. That year, Maawiya Ould Sid Ahmed Taya, an army colonel who had served as president of the military government, was elected president. Opposition parties boycotted the elections. In 1996 elections, members of parties other than the progovernment Republican Democratic and Social Party gained representation in the national legislature. Taya was reelected president in 1997 and again in2003, after military rebels tried unsuccessfully to overthrow him.

In 2005, a group of army officers succeeded in overthrowing Taya while he was out of the country. They set up a Military Council to temporarily rule Mauritania. In a 2006 referendum, voters approvedconstitutional amendments limiting presidential terms. In March, 2007, Maritanians voted in the country's first democratic presidential election. However, no clear winner emerged and a runoff election was held. Sidi Ould Cheikh Abdallahi, a former cabinet member, was elected president. In April,Abdallahi appointed economist Zeine Ould Zeidane as prime minister.