During the long reign of Leopold I (1657–1705) and following the successful defence of Vienna against the Turks in 1683 (under the command of the King of Poland, John III Sobieski), a series of campaigns resulted in bringing most of Hungary to Austrian control by the Treaty of Karlowitz in 1699.