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