In 1587 Maximilian stood as a candidate for the throne of Polish–Lithuanian Commonwealth, following the death of the previous king, Stefan Batory. A portion of the Polish nobility elected Maximilian king, but, as a result of the rather chaotic nature of the election process, another candidate, Sigismund III Vasa, prince of Sweden, grandson of Sigismund I the Old, was also elected. Maximilian attempted to resolve the dispute by bringing a military force to Poland – thereby starting the war of the Polish Succession. His cause had considerable support in Poland, but fewer Poles flocked to his army than to that of his rival. After a failed attempt to storm Kraków in late 1587, he was defeated in January 1588, at Pitschen in Silesia (Battle of Byczyna) by the supporters of Sigismund III (who had since been formally crowned), under the command of Polish hetman Jan Zamojski. Maximilian was taken captive at the battle and was only released a year and half later after the intervention of Pope Sixtus V in the aftermath of the Treaty of Bytom and Będzin. In 1589, he formally renounced his claim to the Polish crown. The inactivity of his brother, the emperor Rudolf II, Holy Roman Emperor in this matter contributed to Rudolf's poor reputation.