In 1605 the Ottomans regained control over the castle as well as the whole region again, maintaining their rule until 1683. Though the Ottomans were mainly engaged in building and fortifying the castle, they also built significant new buildings including mosques, minarets and baths. These structures, along with the contemporary buildings, were destroyed in the siege of 1683 resulting in the liberation of Esztergom - though some Turkish buildings prevailed up to the beginning of the 18th century. The last time the Ottoman forces attacked Esztergom was in 1685. During the following year Buda was liberated as well. During these battles János Bottyán, captain of the cavalry, later the legendary figure of the Rákóczi war of independence disappeared. All that had been rebuilt at the end of the century was destroyed and burnt down during Ferenc Rákóczi's long lasting, but finally successful siege.