Sunni Islam is the strand of Islam practiced by 100% of the population with the majority of them following the Shafi'i school while a minority follows the Hanafi school. Islam has been a part of Somali society since the 7th century.A Country Study: Somalia from The Library of Congress

Muslims first entered modern-day Somalia in the northwestern city of Zeila during prophet Muhammad's lifetime whereupon they supposedly built the Masjid al-Qiblatayn as per local tradition.Lewis, Ioan M. "The Somali conquest of the Horn of Africa." The Journal of African History 1.2 (1960): 213-230.

Practicing Islam reinforces distinctions that further set Somalis apart from their immediate neighbors. Although Pew Research Center has not conducted a survey in Somalia, its Somali-majority northwestern neighbour Djibouti reported a creed breakdown of Muslims which was reported as 77% adhering to Sunnism, 8% as non-denominational Muslim, 2% as Shia, thirteen percent refusing to answer, and a further report inclusive of Somali Region stipulating 2% adherence to a minority sect (e.g. Ibadism, Quranism etc.).

The role of religious functionaries began to shrink in the 1950s and 1960s as some of their legal and educational powers and responsibilities were transferred to secular authorities.Nina J. Fitzgerald, Somalia: Issues, History, and Bibliography-page 48 The position of religious leaders changed substantially after the 1969 revolution and the introduction of scientific socialism. Siad Barre insisted that his version of socialism was compatible with Qur'anic principles and he condemned atheism. Religious leaders, however, were warned not to meddle in politics.

History

Birth of Islam and Middle Ages

Islam was introduced to the northern Somali coast early on from the Arabian peninsula, shortly after the hijra. Zeila's two-mihrab Masjid al-Qiblatayn dates to the 7th century, and is the oldest mosque in the country. Somalis were among the earliest non-Arabs to convert to Islam. Several prominent shaykhs are traditionally credited with spreading Islam in Somalia, including Aw Barhadle, Aw Qudub, Aw Cisman Fiqi Cumar (“Garweyne”), and Aw Cisman Xasan Bin Cakaabir.

In the late 9th century, Al-Yaqubi wrote that Muslims were living along the northern Somali seaboard. He also mentioned that the Adal kingdom had its capital in the city, suggesting that the Adal Sultanate with Zeila as its headquarters dates back to at least the 9th or 10th century. According to I.M. Lewis, the polity was governed by local Somali dynasties, who also ruled over the similarly-established Sultanate of Mogadishu in the littoral Benadir region to the south. Adal's history from this founding period forth would be characterized by a succession of battles with neighboring Abyssinia.

In 1332, the Zeila-based King of Adal was slain in a military campaign aimed at halting the Abyssinian Emperor Amda Seyon I's march toward the city to avenge the slaughtered Christians including a famous monk sent to wage peace and destroyed Churches by the Adalites. When the last Sultan of Ifat, Sa'ad ad-Din II, was also killed by Emperor Dawit I in Zeila in 1410, his children escaped to Yemen, before later returning in 1415. In the early 15th century, Adal's capital was moved further inland to the town of Dakkar, where Sabr ad-Din II, the eldest son of Sa'ad ad-Din II, established a new base after his return from Yemen.

Adal's headquarters were again relocated the following century, this time to Harar. From this new capital, Adal organized an effective army led by Imam Ahmad ibn Ibrahim al-Ghazi (Ahmad "Gurey" or "Gran") that invaded the Abyssinian empire. This 16th century campaign is historically known as the Conquest of Abyssinia (Futuh al-Habash). During the war, Imam Ahmad pioneered the use of cannons and firearms supplied by the Ottoman Empire, which he imported through Zeila and thousands of mercenaries from the Muslim world and nomadic Somalia to wage a 'holy war' against Ethiopian King of Kings. The few Portuguese under Cristóvão da Gama that later that came to assist their Ethoipian coreligionist would tip the scale in their favour.I.M. Lewis, A pastoral democracy: a study of pastoralism and politics among the Northern Somali of the Horn of Africa, (LIT Verlag Münster: 1999), p. 17 Some scholars argue that this conflict proved, through their use on both sides, the value of firearms like the matchlock musket, cannons and the arquebus over traditional weapons.Jeremy Black, Cambridge Illustrated Atlas, Warfare: Renaissance to Revolution, 1492–1792, (Cambridge University Press: 1996), p. 9. By the 16th century, Somali Muslims cultivated religious ties with the BaʿAlawī Husaynis from Hadramawt, adopting aspects of their tradition. In 1503, Shaykh Sharif Abu Bakr al-Aydarus al-ʿAdanī introduced the Qadiriyya Sufi order into the Horn of Africa.

During the Age of the Ajuran, the sultanates and republics of Merca, Mogadishu, Barawa, Hobyo flourished and had a lucrative foreign commerce, with ships sailing to and coming from Arabia, India, Venetia, Persia, Egypt, Portugal and as far away as China. Vasco da Gama, who passed by Mogadishu in the 15th century, noted that it was a large city with houses several storeys high and large palaces in its center, in addition to many mosques with cylindrical minarets.

The city of Mogadishu came to be known as the City of Islam,Society, security, sovereignty and the state in Somalia – Page 116 and controlled the East African gold trade for several centuries.East Africa: Its Peoples and Resources – Page 18 In the 16th century, Duarte Barbosa noted that many ships from the Kingdom of Cambaya in modern-day India sailed to Mogadishu with cloth and spices, for which they in return received gold, wax and ivory. Barbosa also highlighted the abundance of meat, wheat, barley, horses, and fruit on the coastal markets, which generated enormous wealth for the merchants.Sir Reginald Coupland, East Africa and its invaders: from the earliest times to the death of Seyyid Said in 1856, (Russell & Russell: 1965), p. 38. Mogadishu was also the center of a thriving textile industry known as toob benadir, specialized for the markets in Egypt, among other places.

Modern era

Because Muslims believe that their faith was revealed in its complete form to Muhammad, Bidʻah is seen as a major sin. One response was to stress a return to orthodox Muslim traditions and to oppose Westernization totally. The Sufi brotherhoods were at the forefront of this movement, personified in Somalia by Mohammed Abdullah Hassan in the early 20th century. Generally, the leaders of Islamic orders opposed the spread of Western education.Mary-Jane Fox, Political culture in Somalia: tracing paths to peace and conflict-page 123

Another response was to reform Islam by reinterpreting it. From this perspective, early Islam was seen as a protest against abuse, corruption, and inequality; reformers therefore attempted to prove that Muslim scriptures contained all elements needed to deal with modernization. To this school of thought belongs Islamic socialism, identified particularly with Egyptian nationalist Gamal Abdul Nasser. His ideas appealed to a number of Somalis, especially those who had studied in Cairo in the 1950s and 1960s.Federal Research Division, Somalia a Country Study- Page 143

The 1961 constitution guaranteed freedom of religion but also declared the newly independent republic an Islamic state. The first two post-independence governments paid lip service to the principles of Islamic socialism but made relatively few changes. The coup of October 21, 1969, installed a radical regime committed to profound change. Shortly afterward, Stella d'Ottobre, the official newspaper of the Supreme Revolutionary Council (SRC), published an editorial about relations between Islam and socialism and the differences between scientific and Islamic socialism. Islamic socialism was said to have become a servant of capitalism and neocolonialism and a tool manipulated by a privileged, rich, and powerful class. In contrast, scientific socialism was based on the altruistic values that inspired genuine Islam. Religious leaders should therefore leave secular affairs to the new leaders who were striving for goals that conformed with Islamic principles. Soon after, the government arrested several protesting religious leaders and accused them of counterrevolutionary propaganda and of conniving with reactionary elements in the Arabian Peninsula. The authorities also dismissed several members of religious tribunals for corruption and incompetence. When the Three-Year Plan, 1971–1973, was launched in January 1971, SRC leaders felt compelled to win the support of religious leaders so as to transform the existing social structure. On September 4, 1971, Siad Barre exhorted more than 100 religious teachers to participate in building a new socialist society. He criticized their method of teaching in Qur'anic schools and charged some with using religion for personal profit.

The campaign for scientific socialism intensified in 1972. On the occasion of Eid al-Adha, the major Muslim festival associated with the pilgrimage, the president defined scientific socialism as half practical work and half ideological belief. He declared that work and belief were compatible with Islam because the Qur'an condemned exploitation and money lending and urged compassion, unity, and cooperation among Muslims. But he stressed the distinction between religion as an ideological instrument for the manipulation of power and as a moral force. He condemned the antireligious attitude of Marxists. Religion, Siad Barre said, was an integral part of the Somali worldview, but it belonged in the private sphere, whereas scientific socialism dealt with material concerns such as poverty. Religious leaders should exercise their moral influence but refrain from interfering in political or economic matters.

Religious orders always have played a significant role in Somali Islam. The rise of these orders (Tarika, "way" or "path") was connected with the development of Sufism, a mystical sect within Islam that began during the 9th and 10th centuries and reached its height during the 12th and 13th. In Somalia, Sufi orders appeared in towns during the 15th century and rapidly became a revitalizing force. Followers of Sufism seek a closer personal relationship to God through special spiritual disciplines. Escape from self is facilitated by poverty, seclusion, and other forms of self-denial. Members of Sufi orders are commonly called dervishes, from the Persian daraawish (singular darwish, "one who gave up worldly concerns to dedicate himself to the service of God and community"). Leaders of branches or congregations of these orders are given the Arabic title shaykh, a term usually reserved for those learned in Islam and rarely applied to ordinary wadaads (holy men).

Dervishes wandered from place to place teaching. They are best known for their ceremonies, called dhikr, in which states of visionary ecstasy are induced by group- chanting of religious texts and by rhythmic gestures, dancing, and deep breathing. The object is to free oneself from the body and to be lifted into the presence of God. Dervishes have been important as founders of agricultural religious communities called jamaat (singular jamaa). A few of these were home to celibate men only, but usually the jamaat were inhabited by families. Most Somalis were nominal members of Sufi orders.