Following the politics of glasnost, initiated by the last General Secretary of the Communist Party of the Soviet Union, Mikhail Gorbachev, civil unrest and ethnic strife grew in various regions of the Soviet Union, starting with Nagorno-Karabakh, a region of Azerbaijan SSR. The disturbances in Azerbaijan, in response to Moscow's indifference to already heated conflict, resulted in calls for independence and secession from USSR, which subsequently culminated in the events of Black January in Baku. At this time, Ayaz Mutallibov was appointed as the First Secretary of the Azerbaijan Communist Party.
Later in 1990, the Supreme Council of Azerbaijan SSR dropped the Soviet Socialist words from the title, adopted the Declaration of Sovereignty of Azerbaijan Republic, a constituent member of Soviet Union, and restored the modified flag of Azerbaijan Democratic Republic as a state flag. In early 1991, the Supreme Council of Azerbaijan established the institute of presidency, and Ayaz Mutallibov was elected as the first president by the Council. On September 8, 1991, Ayaz Mutallibov was elected as president in nationwide elections, in which he was the only running candidate.
On October 18, 1991, Supreme Council of Azerbaijan adopted a Declaration of Independence, which was affirmed by a nationwide referendum in December 1991, when 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, Azerbaijan lost control of up to 16% of its internationally recognized territory including Nagorno-Karabakh itself. In 1993, democratically elected president Abulfaz Elchibey was overthrown by a military insurrection led by Colonel Suret Huseynov, which resulted in the rise to power of the former leader of Soviet Azerbaijan, Heydar Aliyev. In 1994, Suret Huseynov, by that time a prime minister, attempted another military coup against Heydar Aliyev, though failed, was arrested and charged with treason. In 1995, another coup attempt against Aliyev, by the commander of the military police, Rovshan Javadov, was averted resulting in the killing of the latter and disbanding of Azerbaijan's military police.
Although during his presidency, Aliyev managed to cut down the country's unemployment, reined in the criminal groups, established the fundamental institutions of independent statehood, and brought stability, peace and major foreign investment, 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 became unpopular due to vote fraud, wide-spread corruption and objection to his autocratic regime. The same harsh criticism followed the elections of former Prime Minister Ilham Aliyev, the second leader of New Azerbaijan Party after the death of his father Heydar.