His second term is quite well known. In 1709, during the Great Northern War, Charles XII of Sweden had been defeated by the Russians in the battle of Poltava and took refuge in Ottoman territory, with Peter I of Russia in pursuit. The Ottoman Empire declared war on Russia. Baltacı Mehmet was named the commander ("serdar") of the army. He was able to encircle the Russian army near the Pruth River (now forming the border line between Romania and Moldova), forcing Peter to sue for peace. The Treaty of Pruth stipulated the return of the fortress Azov, which had been annexed by Russia by the Treaty of Karlowitz, to the Ottomans; several Russian fortresses were to be demolished; Peter I promised not to interfere into the affairs of the Polish–Lithuanian Commonwealth and Charles XII was given a free passage to his country.