Northern war in Ukraine
The Great Northern War in Ukraine (1708–1713) — war between the Tsardom of Russia on one hand and the Swedish Empire and the Ottoman Empire on the other. Since the beginning of the Great Northern War, Ukraine, as a satellite of the Tsardom of Russia, had been supplying Moscow troops with manpower, ammunition, fodder and food. With the arrival of Charles XII in Ukraine, hetman Ivan Mazepa concluded the Ukrainian-Swedish Alliance with the King and opposed Peter I. Following the Hetman, the Zaporozhian Army led by kosh otaman Kost Hordienko also joined the Swedes. After the Baturyn tragedy and the Battle of Poltava, the Ukrainian Cossacks, who opposed Peter I, withdrew together with Mazepa and Charles XII to Bendery. After Mazepa's death, Pylyp Orlyk was elected as hetman of Ukraine, and he continued the fight for Ukraine's independence. In 1711 the Ukrainian Cossacks together with the Tatars organized a campaign in Kyiv region. However, due to the insidious retreat of the Tatars, the campaign ended in failure, and Orlyk fell back. All this time, King Charles XII and hetman Orlyk were conducting diplomatic work in the Ottoman Empire and many European capitals in order to organize an anti-Moscow coalition. However, these efforts were unsuccessful. Muscovy managed to avoid any large-scale military action by the Ottoman Empire through diplomatic efforts and bribing of Ottoman officials. Another peace treaty was signed on April 17, 1712. However, on April 30, 1713, Sultan Ahmed III declared a new war — though no significant fighting took place. During 1713, the Muscovy and the Ottoman Empire finally cease hostilities. Charles XII left the territory of the Ottoman Empire and headed to Sweden. War in Ukraine 
After the start of the Russo-Swedish War, the position of the Hetmanate in the Tsardom of Russia got even more complicated. Tsar Peter I constantly demanded more and more manpower, provisions and ammunition from hetman Ivan Mazepa. In addition, Ukrainian Cossacks and officers constantly complained about harassment and extortion conducted by Moscow troops. The civilian population of the Hetmanate was also subjected to looting. In April 1704, a royal order was issued for the Cossack army to fight against detachments of magnates — supporters of the Swedes. Meanwhile, starting in 1706, Mazepa corresponded with Stanislaw Lishchynski (through Princess Dolska). In early October 1708, the army of Charles XII, exhausted and short of ammunition, suffered several local defeats on the road between Mogilev and Smolensk. Additionally, a detachment under the command of Lagerkrun, due to the unfamiliarity with the area, was not able to occupy Starodub which was immediately used by the Moscow army. After the occupation of Starodub and Pochep, Moscow troops blocked the Swedes' last chance to get the food they needed. October 21, 1708 — the Swedish army, not reaching Smolensk, headed to the south — from Kortenichi to the northern borders of Ukraine (Starodub district, crossing the Desna river). Peter I sent an order to the hetman to go to Starodub immediately and unite with general Ifland. After consulting with the colonels, hetman Mazepa decided not to go to Starodub and sent an ambassador to Charles XII with a request for protection. Having learned of the hetman's transition to the Swedes' side, Peter I ordered to capture Mazepa and sent several punitive detachments to prevent mass protests against Moscow in Ukraine, while troops led by Sheremetyev laid siege to Baturyn. Arrival of Swedes in Ukraine 
After the defeat of the Livland Corps, the Swedes had 32,000 soldiers left (instead of the planned 40,000). They had little gunpowder and food, but Charles XII was hoping for a large arsenal and warehouses of hetman Mazepa in Baturyn. On October 23, 1708, Mazepa was in Baturyn. However, on October 24 (November 4), having left an almost impregnable fortress, he crossed the Desna river and met with an advanced detachment of the Swedes. On October 26 (November 6), 1708, in the village of Orlovka (70 km from Baturyn), Mazepa arrived at the headquarters of Charles XII. At that time he had a personal court army, hundreds of elected Cossacks of the Pryluky, Lubny and Myrhorod regiments, several hundred Serdyuks, and three self-formed regiments led by Halahan, Kozhukhovsky and Andriy Malam. The total number of hetman's army was about 3.5-4 thousand soldiers. The rest of the personnel of the three above-mentioned Cossack regiments, led by the commanding Poltava colonel Hryhoriy Hertsyk, together with several Serdyuk regiments led by Chechel, remained in Baturyn. Among the hetman's officers were Ivan Lomykovsky, Vasyl Chuykevych, Pylyp Orlyk, Mykhailo Hamalia, Dmytro Maksymovych, Fedir Myrovych and Ivan Sulyma. Among the colonels were Dmytro Gorlenko of Pryluky, Dmytro Zelensky of Lubny, Konstantin Mokievsky of Chyhyryn, Andriy Kandyba of Korsun, and Danylo Apostol of Myrhorod (the latter soon, together with Halagan, sided with Peter I). On October 28 (November 8), the meeting between the Swedish king and the Ukrainian hetman took place. In early November, the Swedish army was trying to cross the Desna river, which was complicated by the actions of the Moscow's troops under General Hallart. On November 13, the crossing to the west bank of the Desna was completed. Three regiments — Myrhorod, Lubny and Pryluky — refused to join the Moscow army and were awaiting hetman Mazepa's orders. Meanwhile, the siege of Baturyn continued. A. Menshikov had 30,000 soldiers and 20 cannons near Baturyn, and the commander of the fortress, colonel Dmytro Chechel, had 10,000 Cossacks and 40 cannons. The city was well protected, with significant supplies of weapons and food. It could withstand a long siege while waiting for the troops of the hetman and the Swedish king. However, due to the betrayal of captain Ivan Nos, the fortress fell, all its defenders were executed, and large stocks of weapons fell to the Muscovites. After the seizure and burning of Baturyn, Peter I sent 30,000 troops to the Zaporozhian Sich. Colonel Ivan Skoropadsky, who had initially sided with Mazepa, surrendered Starodub without a fight and joined Peter I.

Baturyn's seizure had another consequence: unrest started among the Cossacks. Peter I sent universals to all Ukrainian cities, branding Mazepa a traitor and encouraging people to rebel against the Swedish invaders. Even those Cossacks and colonels who first followed Mazepa, left the Swedish camp and took a wait-and-see attitude. Moscow's troops had also captured Bila Tserkva, which housed hetman's treasury and other warehouses. The Moscow tsar ordered the execution of all supporters of the hetman, punitive detachments were sent throughout Ukraine. Actions of the Swedish-Ukrainian allies 
On November 22, 1708, the Swedish army and Mazepa's troops approached Baturyn, but saw only ruins and fire. The allied army encamped in Romny. Here they received information about the intentions of the King of the Rzeczpospolita Stanislaus to come to their aid, and the promises of the Ottomans to sell the necessary amount of gunpowder, ammunition and lead to the Swedes. Meanwhile, Moscow troops marched towards Hadyach, and the Swedish king was forced to direct the main convoy there to aid his troops. However, severe frosts hit in December, and as Stanislaw Poniatowski wrote: "Before reaching Hadyach, the Swedes lost more than 3,000 soldiers frozen to death, many horses and support staff in carts." On December 22, 1708 (January 2, 1709), the Swedish king left the captured Hadyach and headed back to Romny. During the winter of 1709, local battles took place near Vepryk, Lokhvytsia, Krasnokutsk, Oleshnia, etc. By the spring of 1709, the Swedish soldiers was exhausted by severe winter frosts and constant local clashes with the Moscow army. Charles XII planned to move to Kharkiv, and then to Moscow, but the weather intervened again. Spring floods and thaws washed away the roads and made it impossible for the Swedish army to cross. Due to the damaged roads, the Swedes lost almost their entire convoy. When they reached Kolomak, the allies stopped and were forced to retreat to Opishnia, and on March 2 (13) to Budyshchy. During the campaign in Sloboda Ukraine, the Swedes destroyed and looted villages and towns: Kolomak, Kotelva, Krasnokutsk, Horodne and others among them, but in the battle near Horodne the army were defeated, and Charles himself had barely escaped captivity. During the winter, the Swedish army got significantly reduced in numbers. Poltava was not captured — its garrison, consisting of Moscow soldiers and local Cossacks, repelled all attacks. In addition, the purchase of gunpowder from the Ottomans never took place. The military aid expected by Charles from the Tatars and Ottomans did not arrive as well. This was due to the fact that Peter I met with Kapaji Pasha, the unofficial representative of the Ottoman sultan in the Crimean Khanate, in Azov and gave him a large sum of money;  captured Muslims were also released. Around the same time in Constantinople, during a meeting between Moscow ambassador P. Tolstoy and Grand Vizier Cherlyul Ali Pasha, the ambassador also presented the Vizier with generous gifts from the Moscow tsar. Meanwhile, the "rumors" about Charles XII planning to make peace with Peter and marry his sister Sophia reached Sultan Ahmed III. After all this, Sultan Ahmed III forbade the Crimean Khan Devlet-Girey to "fight the Muscovites" and took a neutral position. While the Tatars and the Poles were in no hurry to help the Swedes, Charles XII and Mazepa got a new ally — the Zaporozhian Sich. Kosh otaman Kost Hordienko, leading the Cossacks, opposed the three Moscow regiments under the command of Colonel Campbell and sent an ambassador to the king with a proposal for an alliance. At the end of March 1709, kosh otaman Kost Hordienko, together with 8,000 Cossacks, swore allegiance to Charles XII and hetman I. Mazepa. Hetman, in turn, allocated 60 thousand thalers from his own treasury for the needs of the army. Battle of Poltava 
During April 1709, Swedish regiments came close to Poltava. Charles XII decided to besiege the town and wait for a decisive battle with Peter I there. On April 24, the first attempt to storm the fortress took place. About 3,000 Swedish soldiers attacked, but the assault failed due to the lack of gunpowder and guns. On May 11, the full siege of the Poltava fortress began. There were 30 cannons and 4.5 thousand Moscow garrison soldiers in Poltava at that time. Meanwhile, the Allies were dealt with another major blow. Tsar Peter sent a combined detachment of infantry of prince D. Golitsyn and the cavalry of H. Holtz to the borders of the Rzeczpospolita. Near the town of Pidkamen, Moscow troops crossed the path of King Stanislaw's army — without the help of von Krassow's troops it was defeated and the King was forced to flee to Warsaw. Two days before the Battle of Poltava, General H. Holtz defeated another Swedish ally —  the detachment of voivode Sapiga. Near Poltava, the Swedes had 4 cannons and not enough gunpowder even for rifles. The Moscow army had 72 cannons (including 40 which they got in Baturyn) and plenty of gunpowder, weapons and ammunition. Meanwhile, Tsar Peter, having gathered a large enough army, advanced to Vorskla. The troops used deceptive maneuvers changing the direction of advance. On June 16 (27), 1709, Charles XII was severely wounded by an accidental bullet near the village Nyzhni Mlyny. The wound caused illness and the king fell ill with a high fever. The Battle of Poltava started on June 27 (July 8). The Swedish army entered the battle with 19,700 soldiers. 6,900 Swedes were killed in the battle, 2,800 were taken prisoner. The losses of the Moscow army are estimated at approx. 1,500 soldiers. It is not known exactly how many Ukrainians died and how many were taken prisoner as Moscow troops treated Ukrainians as "traitors", tortured and executed them. It is known that after the Battle of Poltava approx. 20,000 people (including 16,000 Swedes, as well as Cossacks, civilians, Cossacks with families and children) retreated with Mazepa. Retreat to the south 
In total, approx. 16,000 Swedes retreated in the Swedish-Ukrainian convoy from Poltava. They were pursued by a 12,000-strong Moscow army under the command of M. Golitsyn and R. Bager. They were later accompanied by six regiments of A. Menshikov. Arriving at Perevolochna, the Swedes realized that, after its capture and destruction by Moscow troops, it was impossible to cross there. However, Charles XII, Ivan Mazepa, some of the officers and the wounded (a total of 1,300 Swedes and 1,500 Ukrainians) managed to get to the other side. Meanwhile, Moscow troops approached and surrounded the Swedish camp. On June 30 (July 11) 1709 the besieged 16,000-strong Swedish army surrendered at the mercy of Moscow's troops. The Swedes were arrested and sent deep into Muscovy. Many of them died before the end of the war, many mercenaries who served in the Swedish army went to serve Peter I. On July 17, the Swedish-Ukrainian convoy reached the Buh and the crossing to Ochakovo began. However, it was rather slow. On July 20, prince Volkonsky's Moscow troops approached the camp, captured approx. 300 Swedes and killed more than 500 Ukrainian Cossacks. On August 1 Charles XII, Mazepa and the remains of the convoy moved from Ochakovo to Bendery. Through diplomatic efforts, the Swedish king tried to organize an anti-Moscow alliance with the Ottoman Empire, the Rzeczpospolita and other European countries. However, the Allies were in no hurry to act against Moscow. Meanwhile, Peter I organized an anti-Swedish alliance with Denmark and King Stanislaw, who supported the Swedes, was removed from power in the Rzeczpospolita. Charles and Mazepa found themselves trapped in Bendery as their way to the Rzeczpospolita was blocked by Moscow troops stationed near Chernivtsi. Hetman Ivan Mazepa died on September 21 (October 2), 1709. The Cossacks elected the general secretary Pylyp Orlyk as the new hetman, and he continued Mazepa's work to liberate Ukraine. The anti-Moscow coalition was not forming as quickly as the Allies had hoped. It was not until November 20 (December 1), 1710, that the Ottoman Empire declared war on the Muscovy. The Ottoman army led by Grand Vizier Numan Pasha started the campaign, but the troops moved very slowly, and reached the Danube river only in mid-June 1711. In January 1711, Hetman Pylyp Orlyk began a military campaign in the Right-bank Ukraine with the support of the Tatars of the Crimean Khan Devlet-Girey. The Ukrainian-Tatar army reached Bila Tserkva. Initially, the local population supported Orlyk's army. However, later, the Tatars, violating the agreement, began looting and taking yasir — prisoners. At the same time, the Moscow army launched an offensive, and drove Orlyk into the Ottoman territory. On November 11 (October 31), 1712, the Ottoman Empire declared war on Peter I again but no active hostilities took place. In early 1713 Charles XII left Bendery and returned to Sweden in 1714. The Treaty of Nystad was concluded in 1721, according to which the Swedish prisoners returned home. Consequences of the war 
As a result of the war, Muscovy turned into Russia, and began to get rid of its old enemy, a powerful neighbor who was blocking the access to the Baltic Sea. At the same time, the Battle of Poltava was a colossal disaster not only for Sweden but for entire Europe; it broke the former balance of strength: after the Battle of Poltava the power was transferred from Sweden to Russia, and started to accumulate there; Ukraine lost its independence, legal and international properties, and therefore ceased to exist as a state. See also 

 Great Northern War

References

Russo-Turkish wars
Great Northern War
18th century in Ukraine
Russian–Ukrainian wars