After the Swedish defeat at the Battle of Poltava on 27 June 1709 and the surrender of most of the Swedish army at Perevolochna three days later, Charles XII of Sweden fled together with a few hundred Swedish soldiers and a large number of Cossacks to the Ottoman Empire, where they spent a total of five years.