The first state established in Azerbaijan during the decline of the Abbasid Caliphate was the State of Shirvanshahs. Making use of the chaos that engulfed Baghdad after the death of the Caliph al-Mutawakkil, the representative of the Mazyadids of Arabic origin dynasty which ruled Shirvan, Haytham ibn Khalid, declared Shirvan independent in 861
Haytham ibn Khalid was the first representative of Mazyadids, who assumed the ancient title of Shirvanshah and declared Shirvan as a capital city. His grandson Haysam II strengthened the borders of the state.
He was the first representative of Mazyadids, who assumed the ancient title of Shirvanshah and declared Shirvan as a capital city. Haysam's brother, Yazid, who ruled the neighboring province of Layzan, became Layzanshah. Heysam's grandson Heysam II strengthened the borders of the Shirvanshah state. The events that took place during the reign of his son Ali ibn Haysam, including the Russian attack on the shores of Baku in 913-914, and military failures shook the reputation of the Sirvanshah. In 917, Layzanshah Abu Tahir Yazid, who was able to expand his property to the Kura River in the south and almost to the Samurai in the north, also acquired the title of "Shirvanshah". In 918 he restored the ancient city of Shamakhi and moved the capital here.
The Shirvanshah Muhammad's troops captured Gabala, Barda, and Shabran in 981- 984 The conquest of Darband Emirate, which was formed at the crossing between the Caucasus Mountains and the Caspian Sea and ruled by the Arab Hashimids, by the Shirvanshahs State in 988 was a landmark event. The Shirvanshahs began great creative work in Darband, an ancient Turkic city called "Iron Gate" in the sources. After Darband, the lands of Khursan and Tabasaran were also subjugated, and the rulers of Sheki and Sanariya were vassalized.
In 981-984, Shirvanshah Muhammad ibn Ahmad expanded the territory of the state with the annexation of Gabala, Barda and Shabran. The Seljuq invasion of Arran and Shirvan from 1066 onwards did not weaken the Shirvanshahs, even though they were vassals; By the end of the XI century, the beginning of a political upsurge in Shirvan was already visible. Finally the conquest of Darband Emirate, which was formed at the crossing between the Caucasus Mountains and the Caspian Sea and ruled by the Arab Hashimids, by the Shirvanshahs State in the 1070s was a landmark event. The Shirvanshahs began great creative work in Darband, an ancient Turkic city called "Iron Gate" in the sources. After Darband, the lands of Khursan and Tabasaran were also subjugated, and the rulers of Sheki and Sanariya were vassalized. This rise of Shirvan lasted until the XII century. In the twelfth century, the Shirvanshah state entered its heyday. Mongol invasions in the early XIII century destroyed the capital, Shamakhi. Although the Shirvanshahs accepted the rule of the Mongols, they were able to maintain their statehood. In the middle of the XIV century, the struggle for independence of the Shirvanshahs ensured the independence of Shirvan. At the end of that century, Shirvanshah Sheikh Ibrahim I entered into an alliance with Amir Teymur, who was invading the country from the south and advancing against the Golden Horde Khan Tokhtamish, who invaded the country. Although Ibrahim I, who entered into an agreement with the rulers of Karabakh, Sheki and Ardabil at the beginning of the XV century, was able to unite against the Teymurids, he was unable to unite Azerbaijan. Throughout the XV century, during the rule of the Garagoyunlu (1410-1467) and Aghgoyunlu (1468-1501) states of Azerbaijan, Shirvan province was ruled by Shirvanshahs. The capital Shamakhi was one of the largest centers of crafts and trade in the Middle East. The second half of the XV century is marked by the strengthening of the Safavids in Azerbaijan. The attack of Ismail I, the head of the dynasty, resulted in the defeat of Shirvanshah Farrukh Yasar's army in a bloody battle near the Gulustan fortress and the assassination of the shah. In 1501, Baku fell to the Safavid army. Shirvan, which lost its independence, was incorporated into the Safavids State in 1538
In the X century, the cities of Darband, Baku, Shamakhi, and Shabran became important trade centers. The Arab author, Al-Mugaddasi, who lived during that period, wrote that Baku was the only seaport in this region. In the IX-XI centuries, Baku produced a lot of oil. The oil was widely used in military work, economy, household, and medical work.
When the Arab Caliphate began to weaken and disintegrate in the IX century, especially in the second half, a new state created by the Sajid dynasty appeared in the territory of Azerbaijan. This dynasty took its name from the Turkish commander Abussaj Divdad Saj, who had roots in Central Asia (Usrushana). The activity of Sajids as the representative of the Caliphate in Azerbaijan dates back to 889 In 898, a representative of this dynasty, Muhammad ibn Abussaj, was appointed Arab governor of the South Caucasus. The first capital was the city of Maragha.
The reign of his brother Yusif ibn Abu Saj (901-928) is considered to be the period of the rise of the Azerbaijani statehood. The capital was moved to Ardabil. In 902, Yusif minted silver coins (dirhams) in his name. The borders of the Sajids State covered a vast area to Zanjan in the south, from Ani and Dvin in the west, and to the Caspian Sea in the east. Rulers of places in this area (Shirvan, Sheki, Khachin, Syunik, etc.) paid taxes to the Sajids. Although Azerbaijan formally remained within the borders of the Caliphate, the Sajids had completely independent domestic and foreign policies. Even Yusif ibn Abu Saj stopped sending tribute to Baghdad from 912/913. The most important aspect of his political activity was the unification of all the lands of Azerbaijan.
The byzantine expansion was fought on the western borders of the state. Such important cities as Ardabil, Maragha, Zanjan, Qazvin, Mughan, Dvin, Tabriz, Barda were all under Sajids rule. The country's annual revenue amounted to 4.5 million dirhams. However, the strengthening of the Sajids State and Yusif's independent policy worried the Caliphate. After Yusif, the political activities of his successors were aimed at eliminating the threat from abroad. Although the attacks of the Deylam ruler on Azerbaijan were prevented in 937-938, a few years later, in 941, the Sajids rule in Azerbaijan was ended. The lands of Azerbaijan, which were under the rule of the Sajid dynasty, came under the subordination of the Sallarids from Deylam.
In 941, Deysem, the last representative of the Sajids State in Azerbaijan, was dethroned and the Sallarid dynasty from Deylam came to power. Its first representative Marzban ibn Muhammad (941-957), Deylam ruler's son Salar, unified first southern, then very soon, all territories of Azerbaijan under his power. During the reign of Marzban, the annual tax revenue amounted to 500,000 dinars. In the period of Sallarids’ rule, trading ships of Azerbaijan began sailing in the Caspian Sea.
The capital city of Sallarids State was Ardabil. Marzban ibn Muhammad subjugated north-western lands of Azerbaijan, including the territory of Shirvanshahs control, and conquered of Darband. The lands of Sallarids stretched from Derbent in the north to upper flows of the Euphrates and Tigris Rivers in the south, the Caspian Sea, including Gilan in the east and Kartli-Kakheti, Dvin, and areas around the Van Lake in the west.
In the early X century, as the Sallarids weakened, the Rus, who sailed the Itil (modern Volga) River and sold fur skins to merchants of "warm countries", began raiding the region. The Rus raids in 909-910 and 913-914 brought great disasters to the areas along the Caspian coast. The sacking of Barda in 943-944 and the killing of thousands of the city residents by the Rus raiders was considered a disaster not only in Azerbaijan but also in the entire Islamic world. After six months of occupation, the city was liberated by the Sallarid army. Intensified feudal strife in the 970s and attempts by local rulers to gain independence led to the loss of some of the lands under the Sallarids and their incorporation into the Ravvadis and Shaddadids State.
The State of Ravvadids has played an important role in the political history of Azerbaijan since the end of the X century for almost a century. According to sources, the Arab-born Ravvadid dynasty ruled from 775 to Bazz city , the stronghold of Babeki Khurramites shortly after Tabriz. The representative of this family Ravvad al-Azdi and his sons conducting building work turned Tabriz from a small village to a large city. Abu al-Hayja, one of the representatives of this family, defeated the army led by the Sallarid ruler Ibrahim in 981 and finally ascended the throne of Azerbaijan. After taking Azerbaijan’s southern lands under their reign, Ravvadids took control of Mughan. Tabriz became the capital of the Ravvadis. After taking Azerbaijan’s southern lands under their reign, Ravvadids took control of Mughan. During the reign of the ruler Vahsudan (1020-1059) the inflow of Oghuz tribes settled in Khorasan to Azerbaijan began. Vahsudan welcomed 2,000 Oghuz families (more than 10,000 people), who revolted against the Ghaznavids and found refuge in Azerbaijan in 1028 and gave them land plots to settle. Vahsudan wanted to use the power of the Oghuz tribes in the war against the Byzantine Empire, which was trying to conquer Azerbaijan.
In 1054/55 when Seljuq sultan Toghrul bey, campaigning in Azerbaijan, reached Tabriz, Vahsudan accepted his power. So, Azerbaijan became part of the Seljuq Empire, and soon after, the Ravvadids, who were trying to free themselves from dependence, were removed from power.
Muhammad ibn Shaddad ibn Qurtaq, the founder of the Shaddadid dynasty, led the tribes inhabiting the Dvin and Ani regions and played an active role in the military and political life of the region. The first independent ruler of the Shaddadid dynasty was his son Lashkari (971-978), who was able to take control of Ganja in 971 Barda, Shamkir, Nakhchivan, and other cities of Arran, as well as Dabil and the surrounding lands, came under the rule of the Shaddadids, who called themselves Arranshahs. Fazl ibn Muhammad (985/986-1030/1031), who came to power in 986, as a result of successful campaigns conquered the territories up to Beylagan, Khachin, Sunik, Gorus, Tashir, and Tiflis. In 1026/1027, he defeated the Abkhazian-Georgian army in a battle near Shamkir, and in 1030 he defeated Alan tribes who posed a threat from the north. In 1027, Fazl ibn Muhammad built the Khudafarin bridge over the Araz River, which was of the military and commercial importance. Lashkari II (1034-1049), whom the Azerbaijani poet Qatran Tabrizi called Arranshah in his ode, successfully repulsed the attacks of the union organized by Christian feudal lords, especially from Byzantium, and prevented the Seljuq’ attacks on Ganja in 1046-1047. During the reign of Abu'l-Aswar Shavur (1049/1050-1067) Shirvanshahs were subjugated. Furthermore, he was successful in the wars against Byzantium. Considering that the Seljuqs had become a great power in the region, Abu'l-Aswar Shavur agreed to be a vassal of sultan Toghrul later becoming an ally of the second Seljuqian Sultan Alp Arslan.
Sultan Alp Arslan took the city of Ani from Byzantium in 1065 and gave it to Abu'l-Aswar Shavur, and the rule of the Shaddadids in Ani lasted for 130 years. The rule of this dynasty in Dabil (Dvin) was ended in 1130 by the Seljuqs. During the Shaddadids, crafts, trade, and cities developed in Azerbaijan. Shaddadid ruler Abu'l-Aswar Shavur paid special attention to the city of Ganja. He dug ditches around the city, built fences, and in 1063 built strong fortress gates (architect was Ibrahim ibn Osman).