In 1558, tsar Ivan the Terrible invaded Tartu beginning the Livonian War. Forces under the command of Pyotr Shuiski encircled the town and began the heavy bombardment. In light of this and without any prospect of external help the town surrendered. The local bishop was imprisoned in Moscow, which effectively ended the period of local self-government. In the effect of the Truce of Jam Zapolski of 1582, the city along with southern regions of Livonian Confederation became part of the Polish–Lithuanian Commonwealth. In 1598 it became the capital of the Dorpat Voivodeship of the Duchy of Livonia. A Jesuit grammar school "Gymnasium Dorpatense" was established in 1583. In addition, a translators' seminary was organized in Tartu and the city received its red and white flag from the Polish king Stephen Báthory.