Thököly, aided by the emperor's preoccupation with hostile France, and backed by the Turks and the prince of Transylvania, overruns much of upper Hungary and forces Leopold to restore Hungarian liberties (Treaty of Sopron, 1681) and to recognize his own quasi-sovereignty in north Hungary.
He soon resumes hostilities against the emperor, however, allying himself with the Turks, whose army by 1681 appears very strong, and taking the title of prince over his own dominions.