The city of Baghdad (Arabic: بغداد Baġdād) was established by the Abbasid dynasty as its capital in the 8th century, marking a new era in Islamic history after their defeat of the Umayyad Caliphate. It replaced Seleucia-Ctesiphon, a Sassanid capital 35 km southeast of Baghdad, which was virtually abandoned by the end of the 8th century. Baghdad was the center of the Caliphate during the Islamic Golden Age of the 9th and 10th centuries, growing to be the largest city worldwide by the beginning of the 10th century. It began to decline in the Iranian Intermezzo of the 9th to 11th centuries and was destroyed in the Mongolian invasion in 1258.
 The city was rebuilt and flourished under Ilkhanid rule, but never rose to its former glory. It was again sacked by Timur in 1401 and fell under Turkic rule. It was briefly occupied by Safavid Persia in 1508, but fell to the Ottoman Empire in 1534. With the dissolution of the Ottoman Empire, Baghdad fell under the British Mandate in 1920 and became the capital of the independent Kingdom of Iraq in 1932 (converted to a Republic in 1958).
 As the capital of the modern Republic of Iraq, Baghdad has a metropolitan area estimated at a population of 7,000,000 divided into neighborhoods in nine districts. It is the largest city in Iraq, the second-largest city in the Arab World (after Cairo) and the second-largest city in Western Asia (after Tehran).
 Baghdad was founded on 30 July 762 CE. It was designed by caliph Al-Mansur. According to 11th-century scholar Al-Khatib al-Baghdadi in his History of Baghdad, each course of the city wall consisted of 162,000 bricks for the first third of the wall's height. The wall was 80 ft high, crowned with battlements and flanked by bastions. A deep moat ringed the outer wall's perimeter.
 Thousands of architects, engineers, legal experts, surveyors, carpenters, blacksmiths, diggers, and laborers from across the Abbasid empire were brought in to survey, measure, and excavate the foundations. Ya'qubi, in his Book of Countries, thought there were 100,000 workers involved. "They say that no other round city is known in all the regions of the world," according to Al-Khatib al-Baghdadi. Four equidistant gates pierced the outer walls where straight roads led to the center of the city. The Kufa Gate to the southwest and the Basra Gate to the southeast opened onto the Sarat canal – a key part of the network of waterways that drained the waters of the Euphrates into the Tigris. The Sham (Syrian) Gate to the northwest led to the main road on to Anbar, and across the desert to Syria. To the northeast the Khorasan Gate lay close to the Tigris, leading to the bridge of boats across it.
 The four straight roads that ran towards the center of the city from the outer gates were lined with vaulted arcades containing merchants' shops and bazaars. Smaller streets ran off these four main arteries, giving access to a series of squares and houses; the limited space between the main wall and the inner wall was due to Mansur's desire to maintain the heart of the city as a royal preserve.
 By 766, Mansur's Round City was complete. The ninth-century essayist, polymath, and polemicist al-Jahiz said. "I have seen the great cities, including those noted for their durable construction. I have seen such cities in the districts of Syria, in Byzantine territory, and in other provinces, but I have never seen a city of greater height, more perfect circularity, more endowed with superior merits or possessing more spacious gates or more perfect defenses than Al Zawra (Baghdad), that is to say, the city of Abu Jafar al-Mansur."
 The city had an array of basic services and employed a staff of civil servants. These included night watchmen, lamplighters, health inspectors, market inspectors (who examined the weights and measures as well as the quality of goods), and debt collectors. It also had a police force with a police chief who lived in the caliph's palace.
 The Round City was partially ruined during the siege of 812–813, when caliph Al-Amin was killed by his brother, who then became the new caliph. It never recovered; its walls were destroyed by 912, nothing of them remain, there is no agreement as to where it was located.
 Founder, caliph al-Mansur of the Abbasid caliphate, chose the city's location because of its critical link in trade routes, mild climate, topography (critical for fortification), and proximity to water. All of these factors made the city a center for culture and knowledge. Baghdad is set on the Khurasan Road, which was an established meeting place for caravan routes from all directions. 
 During the construction of the city, gates were placed at the entrances of the major roads into the city, in order to funnel traffic into the city. The Kufah Gate was on a major road that pilgrims took to Mecca, and the Anbar gate linked the bridges over the canals and Euphrates River to the city. These helped in bringing people into the city, and around these entrances, markets allowed travelers to trade. The link in trade routes provided goods to the city, which allowed markets to draw people from all over the Middle East. 
 The markets that developed in Baghdad were sophisticated because of the government's supervision of their products as well as trade amongst each other. An advanced banking system developed as well, allowing further settlement from outsiders. Baghdad's location between the Tigris and Euphrates Rivers created a trade link to further destinations such as China, India, and Armenia, drawing more people, literature, and knowledge to the city. 
 The mild climate and topography made it attractive as well for travelers. Cultures shared knowledge, books, language, and faiths, ultimately creating a "cosmopolitan city" that developed into a learning center.
 Schools were built including the Hanafi and Hanbali schools of law. Law is a critical study for the Muslim people, because of the understanding of justice on Earth as applied to God. The Hanafi today is the largest school of legal thought in the Muslim world, and it was a draw for scholars to the city of Baghdad. Another school was the Bayt al-Hikma (House of Wisdom), which focused on translating texts from various languages into Arabic. This practice began out of a need to supply educated texts from around the world to a growing educated public market. In particular, the Arabic translation of Grecian texts became a substantial market because its primary impetus from the caliphate was to establish a new ideology with a political and scientific base. This translation helped to foster the transition between a primarily oral society, to one centered on a written language. 
 Baghdad's location made it ideal for paper production, which lowered the cost of creating books, making them more prevalent and accessible to more people. As more texts began to be produced, a new market for book vendors opened, and libraries and bookstores appeared in the city. 
 As the public and private sectors of the community became more educated, cultural narrative and secular writing began. In the city, demand for secular literature, designed for entertainment, developed, which shaped the culture of the city's population, as well as the Abbasid Empire as a whole, with Baghdad being a reason for the Golden Age of Islam. At this time, Baghdad was revered as the "center of the world" because of its scholarship. Michael Cooperson says that "Baghdadi scholars were so numerous and so eminent that reference to them could continue to support the 'center of the world' thesis…". Al-Mansur's foundation and construction of the city as well were done by only the best scholars, further fostering the notion of an intellectual city population to support the Golden Age. 
 Al-Mansur's foundation of the city was ultimately based on its potential position as a military arsenal, and its ability to house and support many troops. Large numbers of troops were what originally gave the city such a dense population, but as the army continued to need supplies, more people came to the city for jobs, thus being another reason Baghdad became a center of commerce. Baghdad also being named the new capital of the Abbasid caliphate drew in people for the prestige and name alone. Al-Mansur designated a governor of Baghdad and sent with him a number of elites who gave the city a higher status, drawing more scholars to study.
 At its height, Baghdad was estimated to have over one and half million people living in the city. It may have been the largest city in the world during that time.
 By the 10th century, the city's population was between 300,000 and 500,000.[citation needed] 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 Buwayhids (945–1055) and Seljuk Turks (1055–1135). 
 Nevertheless, the city remained one of the cultural and commercial hubs of the Islamic world until February 10, 1258, when it was sacked by the Mongols under Hulagu Khan. The Mongols massacred most of the city's inhabitants, including the Abbasid Caliph Al-Musta'sim, and destroyed large sections of the city. The canals and dykes forming the city's irrigation system were destroyed. The sack of Baghdad put an end to the Abbasid Caliphate, a blow from which the Islamic civilization never fully recovered. The Mongols placed a Chinese governor in Baghdad after it was captured.
 At this point Baghdad was ruled by the Il-Khanids, part of the Mongolian Empire centered in Iran. The city was reconstructed and flourished under the Mongols. In 1401, Baghdad was again conquered, by Timur ("Tamerlane"). It became a provincial capital controlled by the Jalayirid (1400–1411), Qara Qoyunlu (1411–1469), Aq Quyunlu (1469–1508), and Safavid Persian (1508–1534) – (1624–1638) empires.
 In 1534, Baghdad was conquered by the Ottoman Turks, under the leadership of Suleiman the Magnificent. It was captured by Shah Abbas I of the Safavids in 1624, and retaken by the Ottomans under Murad IV's command in 1638, during the Ottoman-Safavid War of 1623-1639. Under the Ottomans, Baghdad fell into a period of decline, partially as a result of the enmity between its rulers and Safavid Persia. For a time, Baghdad had been the largest city in the Middle East before being overtaken by Constantinople in the 16th century. The city saw a relative revival in the latter part of the 18th century under the Mamluk dynasty. The Nuttall Encyclopedia reports the 1907 population of Baghdad as 185,000.
 
Baghdad remained under Ottoman control until World War I, when on 11 March 1917 it was captured by British forces. After the war, Baghdad was placed under the control of a British Mandate. During the period of British control, the Mandatory administration ordered the construction of several new architectural projects around the city. Iraq was given formal independence by the British in 1932, and increased autonomy in 1946. On 14 July 1958, the Iraqi king, Faisal II, was executed and the monarchy was dissolved after a revolution, forming a republic. The city's population grew from an estimated 145,000 in 1900 to 580,000 in 1950.   During the 1970s Baghdad experienced a period of prosperity and growth because of a sharp increase in the price of petroleum, Iraq's main export. New infrastructure including modern sewers, water, and highway facilities were built during this period. 
 However, the Iran–Iraq War of the 1980s was a difficult time for the city, as money flowed into the army and thousands of residents were killed. Iran launched a number of missile attacks against Baghdad, although they caused relatively little damage and few casualties.
 In 1991 the first Gulf War caused extensive damage to Baghdad's transportation, power, and sanitary infrastructure.[citation needed]
 Baghdad was bombed heavily in March and April 2003 in the 2003 invasion of Iraq, and fell under US control by April 7–9. Additional damage was caused by the severe looting during the days following the end of the war. With the deposition of Saddam Hussein's regime, the city was occupied by U.S. troops. The Coalition Provisional Authority established a three-square-mile (8 km2) "Green Zone" within the heart of the city from which it governed Iraq during the period before the new Iraqi government was established. The Coalition Provisional Authority ceded power to the interim government at the end of June 2004 and dissolved itself.
 On September 23, 2003, a Gallup poll indicated that about two-thirds of Baghdad residents said that the removal of the Iraqi leader was worth the hardships they encountered and that they expected a better life in five years' time. As time passed, however, support for the occupation declined dramatically. In April 2004, USA Today reported that a follow-up Gallup poll in Baghdad indicated that "only 13 percent of the people now say the invasion of Iraq was morally justifiable. In the 2003 poll, more than twice that number saw it as the right thing to do."
 Most residents of Baghdad became impatient with the coalition forces because essential services such as electricity were still unreliable more than a year after the invasion. In the summer of 2004, electricity was only available intermittently in most areas of the city. An additional pressing concern was the lack of security. The curfew imposed immediately after the invasion had been lifted in the winter of 2003, but the city that had once had a vibrant night life was still considered too dangerous after dark for many citizens. Those dangers included kidnapping and the risk of being caught in fighting between security forces and insurgents.[citation needed]
 On 10 April 2007, the United States military began construction of a three-mile (5 km) long 3.5 metre tall wall around the Sunni district of Baghdad. On 23 April, the Iraqi Prime Minister, Nouri Maliki, called for construction to be halted on the wall.
 In 2021, Islamic State of Iraq and the Levant suicide bombers killed 32 people in January and 35 people in July. In April, 82 people died due to a hospital fire.