Sufism first developed in Arabia. Although Muhammad was eventually seen as the model for religious practice and moral behavior par excellence by the early Muslim community, a number of early Muslims sought for ways in which to carry their religious practice beyond the observance of the law or daily rituals required of all Muslims. To do so, these early Muslims drew from the deep well of Near Eastern traditions, including Judaism and Christianity, in order to develop practices and philosophies that centered on cultivating their souls. In the Near East there was a developed and long tradition of asceticism and contemplative practices centered on abstention from excessive food, an emphasis on prayer, and the cultivation of an inwardly-directed mode of devotion.
Most immediately, this meant combining elements of Islamic practice, like prayer and supplication, with modes of asceticism as they found them practiced in the Near East. New habits, including a reduction in physical comfort in the form of food, sleep, and wealth constituted a form of worldly renunciation characteristic of Christian asceticism. Such renunciation was not foreign to the tradition of Muhammad, whose humble lifestyle and approval of such was a feature of the hadith. Early Muslim ascetics actually believed that a simple life of material renunciation was more in keeping with the true message of Muhammad, an issue which could potentially become complicated by the rising fortunes and increasing wealth of the Islamic empire over the 8th century C.E.
The term "Sufi" has become commonplace today and is a catch-all term for all Muslim mystics, but the origin of the word Sufism, let alone the definition of the term, remains somewhat controversial. On the one hand, it may derive from a group of people known as Ahl al-Suffah (the people of Al-Suffah) who lived during the lifetime of Muhammad, in the 7th century. This group consisted of a number of poor émigrés who had accompanied Muhammad to Medina after facing persecution in Mecca. Destitute after having been cast out by their families, and without homes of their own, they lived in the courtyard of Muhammad's mosque. This was a group united by their status as semi-itinerants more than any coherent ideology, but their relative state of poverty resembled an ascetic lifestyle, although they were heavily engaged with the early Muslim community, not isolated from it.
Other interpretations of the term "Sufi" derive meaning from the word "saff" or row, in Arabic, which refers to the "first row standing before God" or the spiritual elect. This is a fanciful etymology, but it reflects the interiority of some definitions of Sufism. Another popular conception held by historians as illustrious as Ibn Khaldoun (1332-1406) and which is related to asceticism is that the term derives from rough woolen garments (the Arabic for wool is "suf") worn by Sufis.
Early Sufis may also have been associated with a fringe movement called the Sufiyya, which was originally marginalized for its overtly antinomian (a term that indicates being released from the obligation to follow religious law) stance. While antinomianism in general may been interpreted as a kind of disregard for the law, in this case it implied a mystical inquiry into why practice is governed by law in the first place. That is, from an antinomian perspective, practicing Islam through prescribed rites such as prayer and fasting is not an end in itself; it is important, but is only a means of disciplining the soul and purifying oneself. That spiritual goal, purification, is the desired result.
It is possible that this early group of Sufis is misrepresented, however, since all the early sources about their movement come from a perspective that was opposed to them, and it may be that they were not as anti-establishment as those sources would have us believe. In any case, these Sufis were not opposed to so-called orthodoxy, and they continued to adhere to mainstream guidelines of Islamic belief and practice. They supplemented these guidelines and practices, however, with attentiveness to cultivating a love of God, exemplified by extra supplications, prayers, poems, dance, and songs devoted to that topic.
The Sufiyya represented the first ideological claims of Sufism. They were the first, according to medieval sources, who strove for an intimate personal relationship with God based on the principles of love. The love of God is mentioned in the Quran, verse 5:54: "He loves them, and they love Him." Love of God was expressed in forms of music and poetry, especially love poetry. God was "the Beloved" and the recitation of such poems accompanied by dancing was often part of a practice whereby the listener was brought to a state of ecstasy.
Sufi literature—comprised of sayings of local figures and teachers, which were then collected by their students—originated in the 9th century C.E. Eventually, as the practices and dogma of Sufism developed to incorporate methods of training and disciplining the soul, thematic works gave way to more elaborate treatises on the "Science of the Hidden" or "'ilm al-batin." An early hub of mysticism developed in Baghdad, the capital of the Islamic empire under the Abbasid dynasty from the 8th century onward. Antecedents of a famous teacher named Al-Junayd ibn Muhammad (d. 910 C.E.) included such luminaries as Al-Hasan al-Basri, a major figure who is often cited as an intellectual forefather by later practitioners of Sufism.
With the consolidation of orthodox schools of law and what is now known as the shariah in the 9th century C.E. came a flourishing of literary and philosophical scholarship in the Islamic world. "Religious Sciences" is a term used for everything from Quranic exegesis to Sufi interpretations of scripture. According to medieval Sufi texts, knowledge of how to relate to the world in a way that acknowledged and fostered love for God was the "Science of the Hidden" or "'ilm al-batin." The language of the "hidden versus the visible" or the "batin versus the zahir" is still in use by Sufi practitioners today. This also referred to knowledge of the self, a term which had both negative and positive implications. One's lower self, or base self, was concerned with earthly necessities and desires. To transcend this lower self successfully was to achieve union with God, the ultimate goal for which Sufis strived.
In contrast to other types of scholarly endeavor, the knowledge resulting from Sufi exploration of knowledge of the inner, hidden, or esoteric (all elements of al-batin) was deemed by its practitioners to be a more inwardly-looking mode of worship. Sufism did not attempt to divorce itself from mainstream Islam, but it did supplement it with this esoteric perspective. It is difficult, partly for this reason, to discern the exact beginnings of Sufism chronologically. There was no foundational moment, event, or single person. Sufis have long claimed that their original model was Muhammad himself, a claim rejected by their mainstream opponents. Early Sufis who flourished in the later 7th and early 8th centuries C.E., such as Al-Hasan al-Basri, are not uniformly recognized as having been Sufis. Still, by the 9th century C.E., the label "Sufi" became accepted in Islamic society, after which point the movement flourished enormously.