Seljuq and Ayyubid periods
With the arrival of the nomadic Seljuq Turks from Central Asia in the late 11th century, Damascus again became the capital of independent states. It was ruled by Abu Sa'id Taj ad-Dawla Tutush I starting in 1079 and he was succeeded by his son Abu Nasr Duqaq in 1095. The Seljuks established a court in Damascus and a systematic reversal of Shia inroads in the city. The city also saw an expansion of religious life through private endowments financing religious institutions (madrasas) and hospitals (maristans). Damascus soon became one of the most important centers of propagating Islamic thought in the Muslim world. After Duqaq died in 1104, his mentor (atabeg), Toghtekin, took control of Damascus and the Burid line of the Seljuq dynasty. Under Duqaq and Toghtekin, Damascus experienced stability, elevated status, and a revived role in commerce. In addition, the city's Sunni majority enjoyed being a part of the larger Sunni framework effectively governed by various Turkic dynasties who in turn were under the moral authority of the Baghdad-based Abbasids.
While the rulers of Damascus were preoccupied in conflict with their fellow Seljuqs in Aleppo and Diyarbakir, the Crusaders, who arrived in the Levant in 1097, conquered Jerusalem, Mount Lebanon and Palestine. Duqaq seemed to have been content with Crusader's rule as a buffer between his dominion and the Fatimid Caliphate of Egypt. Toghtekin, however, saw the Western invaders as a viable threat to Damascus, which, at the time, nominally included Homs, the Beqaa Valley, Hauran, and the Golan Heights as part of its territories. With military support from Sharaf al-Din Mawdud of Mosul, Toghtekin managed to halt Crusader raids in the Golan and Hauran. Mawdud was assassinated in the Umayyad Mosque in 1109, depriving Damascus of northern Muslim backing and forcing Toghtekin to agree to a truce with the Crusaders in 1110. In 1126, the Crusader army led by Baldwin II fought Burid forces led by Toghtekin at Marj al-Saffar near Damascus; however, despite their tactical victory, the Crusaders failed in their objective to capture Damascus.
Following Toghtekin's death in 1128, his son, Taj al-Muluk Buri, became the nominal ruler of Damascus. Coincidentally, the Seljuq prince of Mosul, Imad al-Din Zengi, took power in Aleppo and gained a mandate from the Abbasids to extend his authority to Damascus. In 1129, around 6,000 Isma'ili Muslims were killed in the city along with their leaders. The Sunnis were provoked by rumors alleging there was a plot by the Isma'ilis, who controlled the strategic fort at Banias, to aid the Crusaders in capturing Damascus in return for control of Tyre. Soon after the massacre, the Crusaders aimed to take advantage of the unstable situation and launch an assault against Damascus with nearly 2,000 knights and 10,000 infantry. However, Buri allied with Zengi and managed to prevent their army from reaching the city. Buri was assassinated by Isma'ili agents in 1132; he was succeeded by his son, Shams al-Mulk Isma'il who ruled tyrannically until he was murdered in 1135 on secret orders from his mother, Safwat al-Mulk Zumurrud; Isma'il's brother, Shihab al-Din Mahmud, replaced him. Meanwhile, Zengi, intent on putting Damascus under his control, married Safwat al-Mulk in 1138. Mahmud's reign then ended in 1139 after he was killed for relatively unknown reasons by members of his family. Mu'in al-Din Unur, his mamluk ("slave soldier") took effective power of the city, prompting Zengi—with Safwat al-Mulk's backing—to lay siege against Damascus the same year. In response, Damascus allied with the Crusader Kingdom of Jerusalem to resist Zengi's forces. Consequently, Zengi withdrew his army and focused on campaigns against northern Syria.
In 1144, Zengi conquered Edessa, a crusader stronghold, which led to a new crusade from Europe in 1148. In the meantime, Zengi was assassinated and his territory was divided among his sons, one of whom, Nur ad-Din, emir of Aleppo, made an alliance with Damascus. When the European crusaders arrived, they and the nobles of Jerusalem agreed to attack Damascus. Their siege, however, was a complete failure. When the city seemed to be on the verge of collapse, the crusader army suddenly moved against another section of the walls and was driven back. By 1154, Damascus was firmly under Nur ad-Din's control.
In 1164, King Amalric of Jerusalem invaded Fatimid Egypt, requested help from Nur ad-Din. The Nur ad-Din sent his general Shirkuh, and in 1166 Amalric was defeated at the Battle of al-Babein. When Shirkuh died in 1169, he was succeeded by his nephew Yusuf, better known as Saladin, who defeated a joint crusader-Byzantine siege of Damietta. Saladin eventually overthrew the Fatimid caliphs and established himself as Sultan of Egypt. He also began to assert his independence from Nur ad-Din, and with the death of both Amalric and Nur ad-Din in 1174, he was well-placed to begin exerting control over Damascus and Nur ad-Din's other Syrian possessions. In 1177 Saladin was defeated by the crusaders at the Battle of Montgisard, despite his numerical superiority. Saladin also besieged Kerak in 1183, but was forced to withdraw. He finally launched a full invasion of Jerusalem in 1187 and annihilated the crusader army at the Battle of Hattin in July. Acre fell to Saladin soon after, and Jerusalem itself was captured in October. These events shocked Europe, resulting in the Third Crusade in 1189, led by Richard I of England, Philip II of France and Frederick I, Holy Roman Emperor, though the last drowned en route.
The surviving crusaders, joined by new arrivals from Europe, put Acre to a lengthy siege which lasted until 1191. After re-capturing Acre, Richard defeated Saladin at the Battle of Arsuf in 1191 and the Battle of Jaffa in 1192, recovering most of the coast for the Christians, but could not recover Jerusalem or any of the inland territory of the kingdom. The crusade came to an end peacefully, with the Treaty of Jaffa in 1192. Saladin allowed pilgrimages to be made to Jerusalem, allowing the Crusaders to fulfill their vows, after which they all returned home. Local crusader barons set about rebuilding their kingdom from Acre and the other coastal cities.
Saladin died in 1193, and there were frequent conflicts between different Ayyubid sultans ruling in Damascus and Cairo. Damascus was the capital of independent Ayyubid rulers between 1193 and 1201, from 1218 to 1238, from 1239 to 1245, and from 1250 to 1260. At other times it was ruled by the Ayyubid rulers of Egypt. During the internecine wars fought by the Ayyubid rulers, Damascus was besieged repeatedly, as, e.g., in 1229.
The Al-Salihiyah district, situated on the slopes of Mount Qasioun, was established during the mid-12th century. Its earliest inhabitants were refugees from Jerusalem who settled in Damascus after the city's capture by the Crusaders. The new inhabitants founded the Al-Umariyya Madrasa and the Hanabila Deir, forming the nucleus of the new suburb.
The Ayyubid period saw extensive urban expansion in Damascus, with the construction of numerous madrasas, mosques, and other public institutions both within and outside the Old City walls, reflecting a major phase of urban expansion. Al-Salihiyah continued to grow southward until it reached the city's original fortifications. Prominent educational institutions established during this era included the Al-Murshidiyya, Al-Jaharkasiyya, Al-Sahiba, Al-Shibliyya, Al-Rukniyya, and Al-Shamiyya madrasas.
The Ayyubid period also witnessed the construction of the first congregational mosques to be built since the construction of the Umayyad Mosque approximately five centuries earlier. Unlike the Umayyad Mosque, these mosques were all located outside the Old City walls and included the Hanabila Mosque in Al-Salihiyah, Al-Mardaniyya Mosque and Madrasa (present-day Al-Jisr al-Abyad Mosque), Jarrah Mosque in Al-Shaghour, Al-Tawba Mosque in Uqayba, and Bab Musalla Mosque in Al-Midan. The period also saw the establishment of the Bimaristan al-Qaymari in Al-Salihiyah, one of the city's notable hospitals. During the same period, the Citadel of Damascus was rebuilt following the destruction of the earlier Seljuk-era citadel. The Ayyubid-era madrasas and mausoleums are distinguished by their characteristic red domes, a defining feature of the period's architectural vocabulary. Notable examples include the red dome of Saladin's Mausoleum.