Before gaining independence in the early 1900s, Sudan had been under the rule of several empires, beginning with the Egyptian invasion into Nubia in 2575 B.C. It remained an Egyptian province until it was invaded by Arab traders who spread Islam through southern Sudan. The north remains predominantly Christian today - a remnant of the work of Byzantine missionaries who arrived in the 6th century. During the 1500s, many ethnic groups settled in Sudan including the Dinka, Nuer, Shilluk and Azande.
In 1883, Egypt, under British rule, invaded again, causing a group of Sudanese under the religious leader, Muhammad Ahmad, to revolt. This revolt is known as the Mahdist revolution because many believed that Muhammad Ahmad was the Mahdi - the second prophet who would restore the caliphate. The Mahdists won control of Sudan after a victory against Egyptian forces at Khartoum. After the death of Muhammad Ahmad shortly afterwards, Sudan entered a period of economic and military failure. In 1986, a joint Egyptian and British military expedition entered the weakened Sudan and defeated the caliphate, ending the Mahdist state. Egypt and Britain issued an agreement in 1899 to control Sudan jointly. The two countries occupied Sudan for more than five decades until it was granted independence in 1953.