Born into Polish nobility, Sobieski was educated at the Jagiellonian University and toured Europe in his youth. As a soldier and later commander, he fought in the Khmelnytsky Uprising, the Russo-Polish War and during the Swedish invasion known as the Deluge. Sobieski demonstrated his military prowess during the war against the Ottoman Empire and established himself as a leading figure in Poland and Lithuania. In 1674, he was elected monarch of the Polish–Lithuanian Commonwealth following the sudden and unexpected death of King Michael.