While subordinate to Safavid Persia's Karabakh beylerbeylik (ruled by Ziyad-oglu Qajars) the Armenian meliks were granted a wide degree of autonomy by Safavid Persia over Upper Karabakh, maintaining semi-quasi autonomous control over the region for four centuries, while being under Persian domination. In the early 18th century, Persia's military genius and new ruler, Nadir shah took Karabakh out of control of Ganja khans in punishment for their support of the Safavids, and placed the region directly under his own control. At the same time, the Armenian meliks were granted supreme command over neighboring Armenian principalities and Muslim khans in Caucasus, in return for the meliks' victories over the invading Ottoman Turks in the 1720s.