The earliest evidence of human settlement in the territory of Azerbaijan dates back to the late Stone Ageand is related to the Guruchay culture of the Azykh Cave. The Upper Paleolithic and late Bronze Agecultures 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 Medescame 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 Achaemenid 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. During this period, Zoroastrianism spread in the Caucasus and Atropatene. Caucasian Albanians, the original inhabitants of northeastern Azerbaijan, ruled that area from around the 4th century BC, and established an independent kingdom.
In the 4th and 3rd centuries BC, following the overthrow of the Achaemenid Empire, the southwestern part of modern Azerbaijan was part of the Kingdom of Armenia ruled by the Orontid Dynasty; between the years 189 BC and 428 AD the western half of modern Azerbaijan, including the exclave of Nakhchivan, were included into the Kingdom of Greater Armenia ruled by Armenia's Artaxiad and Arsacid dynasties, the latter itself a branch of the eponymous Arsacid dynasty of Parthia.
After the partition of the Kingdom of Armenia by Iran and Byzantium in 387 AD, the provinces of Artsakh and Utik, which had an ethnically mixed population, passed to Caucasian Albania.
The Iranian Sassanids turned Caucasian Albania into a vassal state in AD 252, while King Urnayrofficially adopted Christianity as the state religion in the 4th century. Despite Sassanid rule, Albania remained an entity in the region until the 9th century, while fully subordinate to Sassanid Iran, and retained its monarchy.
In the first half of the 7th century AD, the Islamic Umayyad Caliphate repulsed both the Sassanids and Byzantines from the Caucasus and turned Caucasian Albania into a vassal state after Christian resistance, led by King Javanshir, was suppressed in 667 AD. Caucasian Albania however, had already come under nominal Muslim rule through the Muslim conquest of Iran, as it was part of the Sassanid territory upon advent of the Muslim conquest. 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 Seljuqs, who entered the area now known as Azerbaijan by 1067.
The pre-Turkic population that lived on the territory of modern Azerbaijani Republic spoke several Indo-European and Caucasian languages, among them Armenian and an Iranian language called the Old Azari language, which was gradually replaced by a Turkic language, the early precursor of the Azerbaijani language of today. 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 "Azarbaijani" or "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, technically vassals of the Seljuq sultans, but 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 as a conquest of Timur.
The local dynasty of the 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 conquest and persecution by the Iranian Safavids in 1501, the last dynasty imposed Shia Islam upon the formerly Sunni population, as it did over its territories in modern-day Iran, as it was battling against the Sunni Ottoman Empire. This, in combination with another series of events, the Safavids laid the foundation for the fact that Iran and the contemporary Republic of Azerbaijan are the only Shia-majority countries ever since.Despite efforts of the Safavids, the Ottomans briefly managed to occupy swaths of present-day Azerbaijan twice over the centuries. Also, Baku and its environs were briefly managed by the Russians in the early 18th century as a consequence of the Russo-Persian War. Despite these very brief intermissions by Safavid Iran's neighboring rivals, the land of what is nowadays Azerbaijan remained under intermittent Iranian rule from the earliest advent of the Safavids up to the course of the 19th century.
After the Safavids, the area was ruled by the Iranian dynasties of Afshar and Zand and briefly by the Qajars, until the latter was eventually forced to cede it to the Russian Empire in the course of the 19th century. However, self-ruling khanates with various forms of independence emerged in the area, especially following the collapse of the Zand dynasty and in the early Qajar era. These khanates, though often self-ruling, were vassals and subjects of the Iranian shah. The khanates exercised control over their affairs via international trade routes between Central Asia and the West. From the late 18th century on, Imperial Russia switched to a more aggressive geo-political stance towards its two neighbors and rivals to the south, namely Iran and Turkey. Following a chain of events that started with the re-subjugation of Georgia into Iran in 1795, Russia would now actively contest and battle with the latter over possession of the Caucasus region which was, for the most part, in the hands of Iran. The successful Russian campaigns in the later stages of the Russo-Persian War (1804–13) were 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.
Following Qajar Iran's loss in the 1804–1813 war, it was forced to concede suzerainty over most of the khanates, along with Georgia and Dagestan to the Russian Empire, per the Gulistan treaty.
The area to the north of the river Aras, amongst which territory lies the contemporary Republic of Azerbaijan, was Iranian territory until it was occupied by Russia in the 19th century. Under the Treaty of Turkmenchaywhich ended the Russo-Persian War (1826-1828), Qajar Iran was forced to recognize Russian sovereignty over the Erivan Khanate, the Nakhchivan Khanate and the remainder of the Lankaran Khanate, comprising the last parts of the soil of the contemporary Azerbaijani Republic that were still in Iranian hands. After incorporation of all Caucasian territories from Iran into Russia, the new border between the two was set at the Aras River, which, upon the Soviet Union's disintegration, subsequently became part of the border between Iran and the Azerbaijan Republic.
Qajar Iran was forced to cede its Caucasian territories to Russia in the 19th century, which thus included the territory of the modern-day Azerbaijan Republic, while as a result of that cession, the Azerbaijani ethnic group is nowadays parted between two nations: Iran and Azerbaijan. Furthermore, the number of ethnic Azerbaijanis in Iran far outnumber those in neighbouring Azerbaijan.
After the collapse of the Russian Empire during World War I, the short-lived Transcaucasian Democratic Federative Republic was declared, constituting what are the present-day republics of Azerbaijan, Georgia, and Armenia.
It was followed by the March Days massacres that took place between 30 March and 2 April 1918 in the city of Baku and adjacent areas of the Baku Governorate of the Russian Empire. When the republic dissolved in May 1918, the leading Musavat party declared independence as the Azerbaijan Democratic Republic (ADR), adopting the name of "Azerbaijan" for the new republic; a name that prior to the proclamation of the ADR was solely used to refer to the adjacent northwestern region of contemporary Iran. 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 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 Bolshevik11th Soviet Red Army invaded it, establishing the Azerbaijan SSR on 28 April 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, Azerbaijanis 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 13 October 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 the Soviet Union, with 80 percent 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 were 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, an autonomous 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 SSRdropped 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 the 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 officially ceased to exist on 26 December 1991.
The early years of independence were overshadowed by the Nagorno-Karabakh war with the ethnic Armenian majority of Nagorno-Karabakh backed by Armenia. By the end of hostilities in 1994, Armenians controlled up to 14–16 percent of Azerbaijani territory, including Nagorno-Karabakh itself. During the war many atrocities were committed including the massacreat Malibeyli and Gushchular, the Garadaghly, Agdaban and the Khojaly massacres. Furthermore, an estimated 30,000 people had been killed and more than a million people had been displaced. Four United Nations Security Council Resolutions (822, 853, 874, and 884) demand 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.
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. A year later, in 1995, another coup was attempted against Aliyev, this time by the commander of the OMON special unit, Rovshan Javadov. The coup 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.
Ilham Aliyev, the son of Heydar Aliyev, assumed as the chairmen of the New Azerbaijan Partyas well as the office of presidency when his father died in 2003. He was reelected to a third term as president in October 2013. He then launched a crackdown on opposition elements. In November, he put two prominent opponents on trial for inciting riots ten months earlier: Ilgar Mammadov, the chairman of the opposition Republican Alternative (REAL); and Ilgar Mammadov, the deputy chairman of the New Equality Party (Musavat). In addition the dissident Islamic theologian Taleh Bagirzada was sentenced to two years’ imprisonment. The opposition newspaper Azadiq was closed down. Three men were sentenced to life in prison on charges of plotting attacks in Baku in a conspiracy with Iran.