Berbers are believed to have reached North Africa from southwestern Asia by at least 2000 b. c.e. They were mentioned in a number of the works by ancient Greek and Roman writers. Many customs of modern Berbers can be recognized in the first century b. c.e. description of Berber life by the Roman writer Sallust.
Merchants from Phoenicia established trading posts that grew into cities in many parts of North Africa after the Berbers settled the region. One of these was the famous city of Carthage, which often hired Berber mercenaries for its armies. Although Berber social organization was primarily based on fiercely independent family groups, they recognized the limited authority of some kings.
One Berber king, Masinissa, was an ally of Carthage. During the long war between Carthage and Rome, however, Masinissa went over to the Roman side. When Carthage surrendered to Rome in 202 b. c.e., North Africa became a Roman protectorate under the local rule of Masinissa. After the Romans destroyed Carthage in 146 b. c.e., they established more direct rule over part of North Africa. However, the area now known as Morocco continued to be independent and was a close ally of Rome under the rule of the Berber king Juba II, from 25 b. c.e. to 24 c. e. Rome finally made Morocco the Roman province of Mauretania in 46 c. e.
By the time the Prophet Muhammad died in 632 c. e., he had united the tribes of the Arabian Peninsula under Islam, the Muslim religion. Islam taught that not only believers, but also governments and societies, should submit to the will of God (Allah). Arab armies invaded and spread Islam throughout the Middle East and North Africa during the seventh and eighth centuries.