Of Turkic origin, the Afsharids ruled Iran 1736–96; at its zenith, the dynasty stretched from Iraq to northern India. Founder Nadir Shah Afshar (r. 1736–47), backed by an army of mostly Sunni Afghans, routed the armies of the Shii Safavid dynasty. Nominally Shii, Nadir Shah forced compromises between Shii and Sunni religious leaders in order to legitimize his claims to Mughal India and Ottoman Iraq. The Shii ulama agreed to renounce explicitly anti-Sunni practices, and the Sunni ulama agreed to acknowledge certain precepts of Shii law. Nadir Shah's religious and political attempts to eradicate Shii Safavid tradition ultimately failed.