From the 15th century, loose groups of independent frontier warriors, the Cossacks, lived in the territory of what is today Ukraine. In the 17th century, they succeeded in establishing a permanent, democratic military organisation with an elected leader, the Hetman. This so-called Hetmanate rose up against Polish rule and, in 1654, placed itself under the protection of the Russian Tsar as part of the Pereyaslav Agreement. However, it retained its organisational independence. Thirteen years later, the Hetmanate was divided: following wars between Poland and Muscovy, the territories on the right bank of the Dnieper River went to Poland, while those on the left and Kyiv fell to the Tsardom.
The Northern War against Sweden and Poland saw Tsar Peter the Great eliminate Cossack regiments by using them as cannon fodder. The Hetmanate faced being crushed. Hetman Ivan Mazepa subsequently switched sides to join Sweden. The Tsar saw this as nothing less than treason. This interpretation continues to be held in Russia to this day. In Ukraine, however, Mazepa is considered a national hero who sought to preserve Cossack self-determination.