The earliest concrete evidence of Muslim presence in East Africa is the foundation of a mosque in Shanga on Pate Island where gold, silver and copper coins dated AD 830 were found during an excavation in the 1980's. The oldest intact building in East Africa is a functioning mosque at Kizimkazi in southern Zanzibar dated AD 1007. It appears that Islam was widespread in the Indian Ocean area by the 14th century. When Ibn Battuta from Maghreb visited the East African littoral in 1332 he reported that he felt at home because of Islam in the area. The coastal population was largely Muslim, and Arabic was the language of literature and trade. The whole of the Indian Ocean seemed to be a "Muslim sea". Muslims controlled the trade and established coastal settlements in South East Asia, India and East Africa. Islam was spread mainly through trade activities along the East African coast, not through conquest and territorial expansion as was partly the case in West Africa, but remained an urban littoral phenomenon for a long time. When the violent Portugese intrusions in the coastal areas occured in the 16th century, Islam was already well established there and almost all the ruling families had ties of kinship with Arabia, Persia, India and even South East Asia owing to their maritime contacts and political connections with the northern and eastern parts of the Indian Ocean. In the end of the 17th and beginning of the 18th centuries the coastal Muslims managed to oust the Portugese with the help of Omani Arabs. These Arabs gradually increased their political influence until the end of the 19th century when European conquerors arrived at the coast of East Africa.
During the time when the Omanis dominated the coast politically, the spread of Islam intensified also in the interior of East Africa. Trade contacts with peoples in the interior, especially the Nyamwezi, gained importance and places like Tabora in Nyamwezi territory and Ujiji at Lake Tanganyika became important entrep"ts in the ever-increasing trade in slaves and ivory. Many chiefs, even in parts of Uganda, converted to Islam and cooperated with the coastal Muslims. Trade served to spread not only Islam, but also the language and culture we call Swahili. Before the establishment of German East Africa in the 1880's the influence of the Swahilis or coastal people was mainly limited to the areas along the caravan routes and around their destinations.
The great expansion of Islam in the interior of Tanganyika began during the German colonial era. After having conquered the coastal area the Germans started hiring Swahilis as civil servants thus creating a cadre of literate Swahilis who accompanied the Germans into the interior. These subordinate administrators, akida, and Muslim soldiers are an important part of the explanation of why Islam spread so much faster in the areas controlled by the Germans than in territories occupied by the British (Kenya and Uganda). The Germans established a government school system along the coast with Swahili as the language of instruction, in contrast to the missionary schools in the interior which used the vernaculars.
Even if many Muslims cooperated with the Germans, there were also large groups who were not benefitted by colonial rule and who were more or less openly oppositional. These groups were primarily found in the poorer sections of the rural population and were attracted to the activities of the Sufi orders. Several orders were active during and after the German era, the most important being the Qadiriyya and Shadhiliyya. Many Sufis played an important role in the Maji Maji uprising (1905-07) against the Germans. The name Maji Maji refers to powerful water (Sw. maji = water) which was thought to give protection against the German weapons. The traditional African ideas of Kinjikitile, the leader of the uprising, were to an extent intertwined with Sufi ideas. Even if our knowledge of Sufi expansion in German East Africa is very limited, the fact remains that Sufi influence was an important factor in the expansion of Islam.
After World War I, when the British took control over Tanganyika, the growth of Islam decreased somewhat. The British system of local government, Indirect Rule, favoured local chiefs rather than Muslims from the coast. Ever-increasing missionary activities as well as the establishment of Christian schools promoted the employment of Christians. Muslims were gradually alienated from the administration and the political scene. From the time around World War II the influence of reformist and anti-colonial movements increased, and during the 1950's Pakistani Muslim preachers regularly visited eastern and southern Africa to promote Muslim renewal and to revive political consciousness among Muslims. This was a reaction to colonial oppression and the increased Christian influence in society. Muslims thus exerted great influence over the independence movements. When the Tanganyika African National Union (TANU) was founded in Daressalaam in 1954, coastal Muslims played an important role. Even in spheres where Islam played a minor part Muslims could hold strategic positions in TANU. The Christian reactions to the independence movement were mixed; many local and Western church leaders discouraged their followers from joining the movement.