Several countries were interested in strategic control of the castle. After the conquest of the Mongol Empire, the Grand Duchy of Lithuania managed to repel the Tatars, retaining control of the fortress until 1434. Under the threat of the Russian and Ottoman empires, the Lithuanians joined the Kingdom of Poland and together they founded the Polish-Lithuanian Commonwealth, making the castle the main defensive outpost against the Turks, who still managed to gain control of the fortress from 1672 to 1699. The Polish-Lithuanian Union regained control for another century, until the Russian Empire seized it and held it until it lost its strategic importance in the 19th century.
Polish-Lithuanian Confederation and Ottoman Empire in one of their battles.