The earliest evidence of human settlement in the territory of Azerbaijan dates to the late Stone Age and is related to the Guruchay culture of the Azykh Cave. The Upper Paleolithic and late Bronze Age cultures are attested in the caves of Tağılar, Damcılı, Zar, Yataq-yeri and in the necropolises of Leylatepe and Saraytepe.
Early settlements included the Scythians in the 9th century BC. Following the Scythians, Iranian Medes came to dominate the area to the south of the Aras. The Medes forged a vast empire between 900–700 BC, which was integrated into the Achaemenids Empire around 550 BC. The area was conquered by the Achaemenids leading to the spread of Zoroastrianism. Later it became part of Alexander the Great’s Empire and its successor, the Seleucid Empire. The Romans also settled in the area during the time of the Roman empire. Caucasian Albanians, the original inhabitants of the area, established an independent kingdom around the 4th century BC. During this period, Zoroastrianism spread in the Caucasus and Atropatene. Ancient Azerbaijanis spoke the Old Azari language.
The Sassanids turned Caucasian Albania into a vassal state in AD 252, while King Urnayr officially adopted Christianity as the state religion in the 4th century. Despite numerous conquests by the Sassanids and Byzantines, Albania remained an entity in the region until the 9th century. The Islamic Umayyad Caliphate repulsed both the Sassanids and Byzantines from the region and turned Caucasian Albania into a vassal state after the Christian resistance, led by King Javanshir, was suppressed in 667. The power vacuum left by the decline of the Abbasid Caliphate was filled by numerous local dynasties such as the Sallarids, Sajids, Shaddadids, Rawadids and Buyids. At the beginning of the 11th century, the territory was gradually seized by waves of Turkic Oghuz tribes from Central Asia. The first of these Turkic dynasties established was the Ghaznavids, which entered the area now known as Azerbaijan by 1030.
The pre-Turkic Azerbaijani population spoke an Iranian language called the Old Azari language, which was gradually replaced by a Turkic language, now known as the Azerbaijani language from the 11th century onward until it became completely extinct in the 16th century. To distinguish it from the Turkic Azerbaijani or Azeri language, this Iranian language, is designated as the Azari language (or Old Azari language), because the Turkic language and people are also designated as “Azari” in the Persian language. However some linguists have also designated the Tati dialects of Iranian Azerbaijan and the Republic of Azerbaijan, like those spoken by the Tats, as a remnant of Azari. Locally, the possessions of the subsequent Seljuq Empire were ruled by atabegs, who were technically vassals of the Seljuq sultans, being sometimes de facto rulers themselves. Under the Seljuq Turks, local poets such as Nizami Ganjavi and Khagani Shirvani gave rise to a blossoming of Persian literature on the territory of present-day Azerbaijan. The next ruling state of the Jalayirids was short-lived and fell under the conquests of Timur.
The local dynasty of Shirvanshahs became a vassal state of Timur’s Empire, and assisted him in his war with the ruler of the Golden Horde Tokhtamysh. Following Timur’s death two independent and rival states emerged: Kara Koyunlu and Ak Koyunlu. The Shirvanshahs returned, maintaining a high degree of autonomy as local rulers and vassals from 861 until 1539. During their persecution by the Safavids, the last dynasty imposed Shia Islam upon the formerly Sunni population, as it was battling against the Sunni Ottoman Empire.
After the Safavids, the area was ruled by the Iranian dynasties of Afshar and Zand and briefly by the Qajars. However de facto self-ruling khanates emerged in the area, especially following the collapse of the Zand dynasty and in the early Qajar era. The brief and successful Russian campaign of 1812 was concluded with the Treaty of Gulistan, in which the shah’s claims to some of the Khanates of the Caucasus were dismissed by Russia on the ground that they had been de facto independent long before their Russian occupation.
The khanates exercised control over their affairs via international trade routes between Central Asia and the West. Engaged in constant warfare, these khanates were eventually incorporated into the Russian Empire in 1813, following the two Russo-Persian Wars. The area to the North of the river Aras, among which the territory of the contemporary republic of Azerbaijan were Iranian territory until they were occupied by Russia. Under the Treaty of Turkmenchay, Persia recognized Russian sovereignty over the Erivan Khanate, the Nakhchivan Khanate and the remainder of the Lankaran Khanate.
In 2007, during the construction of a stadium, constructors discovered the Guba mass grave. Studies by Azerbaijani and foreign scientists have confirmed the human remains found there to be of local residents of various nationalities, including Jews and Lezgians who were killed in the 1918 massacre carried out by Armenians. To date, the remains of 600 people have been found, including about 50 children and 100 women.
After the collapse of the Russian Empire during World War I, Azerbaijan, together with Armenia and Georgia became part of the short-lived Transcaucasian Democratic Federative Republic. When the republic dissolved in May 1918, Azerbaijan declared independence as the Azerbaijan Democratic Republic (ADR). The ADR was the first modern parliamentary republic in the Muslim world. Among the important accomplishments of the Parliament was the extension of suffrage to women, making Azerbaijan the first Muslim nation to grant women equal political rights with men. Another important accomplishment of ADR was the establishment of Baku State University, which was the first modern-type university founded in Muslim East.
By March 1920, it was obvious that Soviet Russia would attack the much-needed Baku. Vladimir Lenin said that the invasion was justified as Soviet Russia could not survive without Baku’s oil. Independent Azerbaijan lasted only 23 months until the Bolshevik 11th Soviet Red Army invaded it, establishing the Azerbaijan SSR on April 28, 1920. Although the bulk of the newly formed Azerbaijani army was engaged in putting down an Armenian revolt that had just broken out in Karabakh, Azeris did not surrender their brief independence of 1918–20 quickly or easily. As many as 20,000 Azerbaijani soldiers died resisting what was effectively a Russian reconquest.
On October 13, 1921, the Soviet republics of Russia, Armenia, Azerbaijan, and Georgia signed an agreement with Turkey known as the Treaty of Kars. The previously independent Naxicivan SSR would also become an autonomous ASSR within the Azerbaijan SSR by the treaty of Kars. On the other hand, Armenia was awarded the region of Zangezur and Turkey agreed to return Gyumri (then known as Alexandropol).
During World War II, Azerbaijan played a crucial role in the strategic energy policy of Soviet Union, with most of the Soviet Union’s oil on the Eastern Front being supplied by Baku. By the Decree of the Supreme Soviet of the USSR in February 1942, the commitment of more than 500 workers and employees of the oil industry of Azerbaijan was awarded orders and medals. Operation Edelweiss carried out by the German Wehrmacht targeted Baku because of its importance as the energy (petroleum) dynamo of the USSR. A fifth of all Azerbaijanis fought in the Second World War from 1941 to 1945. Approximately 681,000 people with over 100,000 of them women went to the front, while the total population of Azerbaijan was 3.4 million at the time. Some 250,000 people from Azerbaijan were killed on the front. More than 130 Azerbaijanis were named Heroes of the Soviet Union. Azerbaijani Major-General Azi Aslanov was twice awarded the Hero of the Soviet Union.
Following the politics of glasnost, initiated by Mikhail Gorbachev, civil unrest and ethnic strife grew in various regions of the Soviet Union, including Nagorno-Karabakh, a region of the Azerbaijan SSR. The disturbances in Azerbaijan, in response to Moscow’s indifference to already heated conflict, resulted in calls for independence and secession, which culminated in Black January in Baku. Later in 1990, the Supreme Council of the Azerbaijan SSR dropped the words “Soviet Socialist” from the title, adopted the Declaration of Sovereignty of the Azerbaijan Republic and restored flag of the Azerbaijan Democratic Republic as a state flag. On 18 October 1991, the Supreme Council of Azerbaijan adopted a Declaration of Independence which was affirmed by a nationwide referendum in December 1991, when the Soviet Union was officially dissolved.
The early years of independence were overshadowed by the Nagorno-Karabakh War with neighboring Armenia. By the end of hostilities in 1994, Armenians controlled up to 16 percent of Azerbaijani territory, including Nagorno-Karabakh itself. An estimated 30,000 people had been killed and more than a million had been displaced. Four United Nations Security Council Resolutions (822, 853, 874, and 884) demands for “the immediate withdrawal of all Armenian forces from all occupied territories of Azerbaijan.” Many Russians and Armenians left Azerbaijan during the 1990s. According to the 1970 census, there were 510,000 ethnic Russians and 484,000 Armenians in Azerbaijan. The single most prominent example was the Khojaly Massacre, ruled a genocide by the Memorial Human Rights Center, Human Rights Watch and other international observers.
In 1993, democratically elected president Abulfaz Elchibey was overthrown by a military insurrection led by Colonel Surat Huseynov, which resulted in the rise to power of the former leader of Soviet Azerbaijan, Heydar Aliyev. In 1994, Surat Huseynov, by that time a prime minister, attempted another military coup against Heydar Aliyev, but Huseynov was arrested and charged with treason.In 1995, another coup attempt against Aliyev, by the commander of the OMON special unit, Rovshan Javadov, was averted, resulting in the killing of the latter and disbanding of Azerbaijan’s OMON units. At the same time, the country was tainted by rampant corruption in the governing bureaucracy. In October 1998, Aliyev was reelected for a second term. Despite the much improved economy, particularly with the exploitations of Azeri-Chirag-Guneshli oil field and Shah Deniz gas field, Aliyev’s presidency was criticized due to suspected vote fraud and corruption.