After the Battle of Poltava in 1709, he escaped together with Hetman Ivan Mazepa and king Charles XII of Sweden to Bender in the Principality of Moldavia, 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 Orlyk wrote one of the first state constitutions in Europe. This Constitution of Pylyp Orlyk was confirmed by Charles XII and it also names him as "the protector of Ukraine".