According to chronicles from the Byzantine Empire, the Aq Qoyunlu are first attested in the district of Bayburt south of the Pontic mountains from at least the 1340s, and a number of their leaders, including the dynasty's founder, Qara Osman, married Byzantine princesses. The Aq Qoyunlu Turkomans first acquired land in 1402, when Timur granted them all of Diyar Bakr in present-day Turkey. For a long time, the Aq Qoyunlu were unable to expand their territory, as the rival Kara Koyunlu or "Black Sheep Turkomans" kept them at bay. However, this changed with the rule of Uzun Hasan, who defeated the Black Sheep Turkoman leader Jahān Shāh in 1467. After the defeat of a Timurid leader, Abu Sa'id Mirza, Uzun Hasan was able to take Baghdad along with territories around the Persian Gulf. He expanded into Iran as far east as Khorasan. However, around this time, the Ottoman Empire sought to expand eastwards, a serious threat that forced the Aq Qoyunlu into an alliance with the Karamanids of central Anatolia. As early as 1464, Uzun Hasan had requested military aid from one of the Ottoman Empire's strongest enemies, Venice. Despite Venetian promises, this aid never arrived and, as a result, Uzun Hassan was defeated by the Ottomans at the Battle of Otlukbeli in 1473, though this did not destroy the Aq Qoyunlu. When Uzun Hasan died early in 1478, he was succeeded by his son Khalil Mirza, but the latter was defeated by a confederation under his younger brotherYa'qub at the Battle of Khoy in July. Ya'qub, who reigned from 1478 to 1490, sustained the dynasty for a while longer. However, during the first four years of his reign there were seven pretenders to the throne who had to be put down. Following Ya'qub's death, civil war again erupted, the Aq Qoyunlus destroyed themselves from within, and they ceased to be a threat to their neighbors. The early Safavids, who were followers of the Safaviyyareligious order, began to undermine the allegiance of the Aq Qoyunlu. The Safavids and the Aq Qoyunlu met in battle in the city of Nakhchivan in 1501 and the Safavid leader Ismail I forced the Aq Qoyunlu to withdraw. In his retreat from the Safavids, the Aq Qoyunlu leader Alwand destroyed an autonomous state of the Aq Qoyunlu in Mardin. The last Aq Qoyunlu leader, Murad, brother of Alwand, was also defeated by the same Safavid leader. Though Murād briefly established himself in Baghdad in 1501, he soon withdrew back to Diyar Bakr, signaling the end of the Aq Qoyunlu rule.
Governance
The leaders of Aq Qoyunlu were from the Begundur or Bayandur clan of the Oghuz Turks and were considered descendants of the semi-mythical founding father of the Oghuz, Oghuz Khagan. The Bayandurs behaved like statesmen rather than warlords and gained the support of the merchant and feudal classes of Transcaucasia. With the conquest of Iran, not only did the Aq Qoyunlu center of power shift eastward, but Iranian influences were soon brought to bear on their method of government and their culture. In the Iranian provinces Uzun Hassan maintained the preexisting administrative system along with its officials, whose families had in some cases served under different dynasties for several generations. There were only four top civil posts, all held by Iranians, in Uzun Hassan's time: those of the vizier, who headed the great council ; the mostawfi al-mamalek, who was in charge of the financial administration; the mohrdar, who affixed the state seal; and the marakur "stable master", who looked after the royal court. In letters from the Ottoman Sultans, when addressing the kings of Aq Qoyunlu, such titles as ملك الملوك الأيرانية "King of Iranian Kings", سلطان السلاطين الإيرانية "Sultan of Iranian Sultans", شاهنشاه ایران خدیو عجم Shāhanshāh-e Irān Khadiv-e Ajam "Shahanshah of Iran and Ruler of Persia", Jamshid shawkat va Fereydun rāyat va Dārā derāyat "Powerful like Jamshid, flag of Fereydun and wise like Darius" have been used. Uzun Hassan also held the title Padishah-i Irān "Padishah of Iran", which was re-adopted again in the Safavid times through his distaff grandson Ismail I, founder of the Safavid Empire.
Amidst the struggle for power between Uzun Hasan's grandsons Baysungur and Rustam, their cousin Ahmed Bey appeared on the stage. Ahmed Bey was the son of Uzun Hasan's eldest son Uğurlu Muhammad, who, in 1475, escaped to the Ottoman Empire, where the sultan, Mehmed the Conqueror, received Uğurlu Muhammad with kindness and gave him his daughter in marriage, of whom Ahmed Bey was born. According to Hasan Rumlu's Ahsan al-tavarikh, in 1496-7, Hasan Ali Tarkhani went to the Ottoman Empire to tell Sultan Bayezid II that Azerbaijan and Persian Iraq were defenceless and suggested that Ahmed Bey, heir to that kingdom, should be sent there with Ottoman troops. Beyazid agreed to this idea, and by May 1497 Ahmad Bey faced Rustam near Araxes and defeated him.