During the Great Northern War Sweden and Hetman Ivan Mazepa formed an alliance in 1708 against Peter I of Russia. But after the defeat at Poltava on 28 June 1709, parts of the Swedish army under king Charles XII and Hetman Ivan Mazepa together with his loyal cossacks had to flee to Bender in Ottoman Turkey where Mazepa soon died. Pylyp Orlyk was then chosen as a Hetman in exile by the cossacks and the Swedish king Charles XII. While in Bender Pylyp Orlyk wrote one of the first state constitutions in Europe. This constitutions was confirmed by Charles XII and it also names him as "the protector of Ukraine".