The emperor personally took part in the campaign against the Swedes, that ended with a defeat at the Battle of Jankau on 6 March, 1645. The Swedish army under Lennart Torstensson then advanced to Vienna. To raise morale in the city, the emperor circled the city in a large procession with an image of the Virgin Mary. As the Swedish army drew closer, Ferdinand left the city. Archduke Leopold Wilhelm managed to drive off the opponents. At times Ferdinand managed to get Prince George I Rákóczi of Transylvania, an ally of France and Sweden, on his side. In the 1645 "Peace of Linz" the Emperor had to guarantee the Hungarian estates the right of imperial representation and freedom of religion for the Protestants, which prevented the Counter-reformation and future Absolutist rule in Hungary.