Treaty of Karlowitz
The fortress was returned to Poland as a result of the Treaty of Karlowitz (1699).