During "the Deluge", when the Swedish armies invaded Polish–Lithuanian Commonwealth, which was already struggling with Muscovy, the Voivode of Poznań, Krzysztof Opaliński, surrendered Greater Poland to Swedish king Charles Gustav. Other areas also surrendered in rapid succession. Almost the whole country followed suit, with the Swedes entering Warsaw unopposed in August 1655 and John Casimir fleeing to Silesia, where he took refuge in the town of Oberglogau () staying there in a local castle from October 17, 1655 until December 18 of the same year.