In the Middle Ages, the Duchy of Austria was an autonomous state within the Holy Roman Empire, ruled by the House of Habsburg, and the Kingdom of Hungary was a sovereign state outside the empire. In 1526, Hungary was defeated and partially conquered by the Ottoman Empire. King Louis II of Hungary and Bohemia had no legitimate heir and died young in the Battle of Mohács. Louis II's brother-in-law, Ferdinand I of Habsburg, was elected King of Hungary by a rump Parliament in Pozsony in December 1526. The Ottomans were subsequently driven out of Hungary by international Western Christian forces led by Prince Eugene of Savoy between 1686 and 1699. From 1526 to 1804, Hungary was ruled by the Habsburg dynasty as kings of Hungary, but remained nominally and legally separate from the other lands of the Habsburg Monarchy.