Military campaigns of Tokhtamysh and Amir Teymur. The deepening economic crisis and protracted wars in the second half of the XIV century completely weakened the Hulagu state, and after the collapse of the state, the southern part of Azerbaijan was occupied in 1359 by the Mongol dynasty of Jalarids. In 1367, the Shirvanshah state also became dependent on the Jalarids. However, the Jalarids weren’t fully established in Azerbaijan. In 1385, the khan of the Golden Horde Tokhtamysh captured Darband and Shirvan, and besieged Tabriz. Although he received 250 gold tumens from the people of Tabriz, he entered the city, massacred the population. Tokhtamish, who plundered Maragha, Marand and Nakhchivan, returned to the Golden Horde with 200,000 captives.
In 1386, Azerbaijan was attacked by Amir Teymur. Unlike Teymur, Tokhtamish, who captured Sultaniye, Tabriz, Nakhchivan and other cities during the first campaign (1386-1388), tried to develop economy and increase the income he collected from the territories. Teymur entrusted the administration of Azerbaijan and neighboring provinces to his son Miranshah.
Amir Teymur recaptured the city of Tabriz in 1392 during the second campaign, to organize the conquest of Azerbaijan and neighboring regions. The Alinja fortress, where the treasury of Sultan Ahmad Jalayir was kept, was captured by Teymur only in 1400, during the third campaign, after a 14-year siege. Azerbaijan played a key strategic role in the struggle of Amir Teymur against Tokhtamysh.
Strengthening of the Shirvanshah state. The policy of Ibrahim I. Shirvanshah Hushang's wrong policy and dependence on the Jalarids led to an uprising in Shirvan and killing of Hushang. Ibrahim, a local feudal lord, came to power in 1382, thus beginning the reign of the dynasty of Darbandies (1382-1538) in Shirvan. Shirvanshah Ibrahim I (1382-1417) tried to use the fierce rivalry between Teymur and Tokhtamysh for the region to save the northern lands of Azerbaijan from great devastation and to preserve the Shirvan reign.
Amir Teymur recognized Shirvanshah Ibrahim I as the ruler of Shirvan, and entrusted him with an important task, which was the protection of the northern borders. Ibrahim I, together with Teymur, took part in the campaigns against the Ottoman sultan Beyazid in 1399-1402. Ibrahim I had great political influence in the South Caucasus region, and his allies were the ruler of Sheki Seydi Ahmad and the Georgian tsar Georgi VII. Shirvanshah I Ibrahim skillfully took advantage of the favorable historical conditions and united Ganja and Karabakh under his kingdom. Ibrahim I, who remained loyal to Teymur until his death, changed his policy immediately after Teymur’s decease. In 1405, he and his allies defeated Teymurid Omar's army on the banks of the Kura River. In 1406, he took advantage of the revolt of the people of Tabriz against the Temurids and entered Tabriz, and the people met him with respect and recognized him as the ruler of Tabriz. However, he received the news that Jalarid Sultan Ahmad and Gara Yusif Garagoyunlu were approaching Tabriz and left the city.