Islamic psychology or ʿilm al-nafs (Arabic: علم النفس), the science of the nafs ("self" or "psyche"), is the medical and philosophical study of the psyche from an Islamic perspective and addresses topics in psychology, neuroscience, philosophy of mind, and psychiatry as well as psychosomatic medicine. In Islam, mental health and mental illness were viewed with a holistic approach. This approach emphasized the mutual connection between maintaining adequate mental wellbeing and good physical health in an individual. People who practice Islam thought it was necessary to maintain positive mental health in order to partake in prayer and other religious obligations.
Concepts from Islamic thought have been reexamined by Muslim psychologists and scholars in the 20th and 21st centuries.
In the writings of Muslim scholars, the term Nafs (self) was used to denote individual personality and the term fitrah for human nature. Nafs encompassed a broad range of faculties including the qalb (heart), the ruh (soul), the aql (intellect) and irada (will). Muslim scholarship was strongly influenced by Greek as well as by the study of scripture, drawing particularly from Galen's understanding of the four humors of the body.
In medieval Islamic medicine in particular, the study of mental illness was a speciality of its own, and was variously known as al-‘ilaj al-nafs (approximately "curing/treatment of the ideas/soul/vegetative mind), al-tibb al-ruhani ("the healing of the spirit," or "spiritual health") and tibb al-qalb ("healing of the heart/self," or "mental medicine").
The Classical Arabic term for the mentally ill was "majnoon" which is derived from the term "Jenna", which means "covered". It was originally thought that mentally ill individuals could not differentiate between the real and the unreal. However, due to their nuanced nature treatment on the mentally ill could not be generalized as it was in medieval Europe  This term was gradually redefined among the educated, and was defined by Avicenna as "one who suffers from a condition in which reality is replaced with fantasy".
In the Islamic world, special legal protections were given to the mentally ill. This attitude was reinforced by scripture, as exemplified in Sura 4:5 of the Qur'an:
Do not give your property which God assigned you to manage to the insane: but feed and clothe the insane with this property and tell splendid words to them.— "
This Quranic verse summarized Islam's attitudes towards the mentally ill, who were considered unfit to manage property but must be treated humanely and be kept under care by either a guardian or the state.
During the 8th to 15th centuries of the Gregorian calendar, the Islamic Golden Age occurred. This marked a time of numerous advancements and discoveries in Islamic arts and sciences. This led to Islam scholars understanding that certain conditions can alter an individual's spiritual and psychological states. Those who were seen as majnoon (madness) were believed to have an imbalance in their spiritual and psychological states. A prominent philosopher during this time was al-Ghazali (1058-1111). He proposed that maintaining a balanced connection between the spiritual and psychological conditions within the body was vital in order to sustain a close relationship with God. al-Ghazali further explained that divergence from this interconnectedness could result in abnormalities within an individual's mental health.
Muhammad ibn Zakariya al-Razi (865 – 925), known as Rhazes in the western tradition, was an influential Persian physician, philosopher, and scientist during the Golden Age of Islam, and among the first in the world to write on mental illness and psychotherapy. As chief physician of Baghdad hospital, he was also the director of one of the first psychiatric wards in the world. Two of his works in particular, El-Mansuri and Al-Hawi, provide descriptions and treatments for mental illnesses.
Abu-Ali al-Husayn ibn Abdalah ibn-Sina (980-1030), known to the west as Avicenna, was a Persian polymath who is widely regarded for his writings on such diverse subjects as philosophy, physics, medicine, mathematics, geology, Islamic theology, and poetry. In his most widely celebrated work, the Canon of Medicine (Al-Qanun-fi-il-Tabb), he provided descriptions and treatments for such conditions as insomnia, mania, vertigo, paralysis, stroke, epilepsy, and depression as well as male sexual dysfunction. He was a pioneer in the field of psychosomatic medicine, linking changes in mental state to changes in the body.
Abu Zayd al-Balkhi (850-934) was a Muslim psychologist and physician during the Islamic Golden Age. His many contributions were vital to the understanding of mental health as well as how to treat various mental illnesses. Al-Balkhi is famous for his work titled “Sustenance of the Body and Soul.” In it, he encouraged other physicians to treat the body and mind as a whole and thus take a holistic approach to medicine. This thinking is significant because it laid the foundation for a psychophysiological approach to healthy living in Medieval Islam. In al-Balkhi’s writings, he explains that the soul experiences an array of emotions such as distress, sadness, and fear when the body undergoes physical illnesses.
The establishment of cognitive therapy is credited to al-Balkhi. When his patients experienced distress, he developed an approach that motivated them to think positively using healthy cognitions. al-Balkhi and other important Islamic scholars also implemented the technique of reciprocal inhibition when treating their patients. Furthermore, al-Balkhi also places emphasis on how environmental factors, such as housing, exercise, and nutrition, can affect a person’s mental wellbeing. al-Balkhi’s contributions also consisted of identifying the difference between psychosis and neurosis. He categorized neuroses into four groups: obsessions, sadness and depression, fear and anxiety, and anger and aggression. The analysis al-Balki made in medieval Islamic psychology is still relevant to modern psychology.
The mental health disorder melancholia was frequently analyzed during medieval Islam. Islamic scholars described melancholia as a state of constant sadness that people endured. It was proposed that high amounts of black bile in the body would result in this mental illness. The location of the excess black bile in the body would result in varied symptoms of this mental health condition. The state of sadness people experience could be categorized into three different types: sadness from trauma or stress, sadness from external factors, such as inadequate nourishment of the body, or everyday sadness. This classification system is similar to how present models analyze depression. During medieval Islam, melancholia was considered to be variations of other health issues, such as epilepsy and mania.
The earliest bimaristans were built in the 9th century, and large bimaristans built in the 13th century contained separate wards for mentally ill patients.
In addition to medication, treatment for mental illness might include baths, music, talk therapy, hijama (cupping), and aromatherapy. Scholars and physicians of this time period were some of the first to emphasize psychosomatic medicine, the emphasis placed on the relationship between illness of the mind and problems in the body. Medicine would be prescribed in order to re-balance the four humors of the body, an imbalance of which might result in psychosis. Insomnia, for example, was thought to result from excessive amounts of the dry humors which could be remedied by the use of humectants.