The city was founded in 762 by the Abbasid caliph al-Mansur, replacing Damascus as the capital of a Muslim empire stretching from North Africa to Persia. Within a generation of its founding, Baghdad become a leading centre of learning and commerce. Some sources suggest that it contained over a million inhabitants, though the actual figure may have been a fraction of this. Many of the tales in the Thousand and One Nights are set in the Baghdad of this period - dubbed the "City of Peace" by Scheherazade - and feature its most celebrated ruler, the Caliph Haroun al-Raschid.
Baghdad's early meteoric growth slowed due to troubles within the caliphate, including relocations of the capital to Samarra (during 808-819 and 836-892), the loss of the western and easternmost provinces, and periods of political domination by the Iranian Buyids (945-1055) and Seljuk Turks (1055-1135). Nevertheless, the city remained one of the cultural and commercial hubs of Dar al-Islam until February 10, 1258, when it was sacked by the Mongols under Hulagu Khan. The Mongols massacred 800,000 of the city's inhabitants, including the Abbasid caliph al-Mutasim, and destroyed large sections of the city. The sack of Baghdad put an end to the Abbasid caliphate, a blow from which the Arab civilization never fully recovered.
In 1401, Baghdad was again sacked by the Mongols, led by Timur ("Tamerlane"). It became a provincial capital controlled by the Jalayirid (1400–1411), Qara Quyunlu (1411–1469), Aq Quyunlu (1469–1508), and Safavid (1508–1534) dynasties. In 1534, Baghdad was conquered by the Ottoman Turks.
Baghdad remained under Ottoman rule until the establishment of the kingdom of Iraq under British control in 1921, followed by formal independence in 1932 and full independence in 1946. The city's population grew from an estimated 145,000 in 1900 to 580,000 in 1950.
The Gulf War of 1991 caused severe damage to Baghdad, particularly its transportation, power, and sanitary infrastructure. The city was also bombed heavily in March and April 2003 in the 2003 Iraq war. Additional damage was caused by the severe looting during the following days. With the deposition of Saddam Hussein's regime, the city was occupied by U.S. troops and became the seat of the interim Coalition Provisional Authority, the body established to govern the country until a new Iraqi government took shape.
The city's main airport is Saddam International Airport, renamed "Baghdad International Airport" after its capture by US forces in April of 2003.
Points of interest include the National Museum of Iraq, whose priceless collection of artifacts was looted after the capture of Iraq by US forces, the iconic Hands of Victory arches, and the Baghdad zoo.
A largely Shiite district of Baghdad, Saddam City, seized a certain amount of autonomy in the week following the capture. Its leaders expressed uncertainty as to whether it would return to the control of a future national civil government.