In a final reversal however, Napoleon I finally vanquished Russia at the Battle of Friedland in July 1807. The alliance between France and the Ottoman Empire was maintained, and a peace settlement was brokered between Russia and the Ottomans, but the territories the Ottomans had been promised (Moldavia and Wallachia) through the Treaty of Tilsit were never returned, although the Ottomans themselves had complied with their part of the agreement by moving their troops south of the Danube. Faced with betrayal by Russia, and the failure of France to have the agreement enforced, the Ottoman Empire, now ruled by Sultan Mahmud II, finally signed on 5 January 1809 a Treaty of Peace, Commerce and Secret Alliance with Great Britain, which was now at war with both France and Russia. In 1812, through the Treaty of Bucharest, the Ottoman Empire and Russia agreed to make peace, just as Russia was anxious to liberate this southern front in anticipation of Napoleon's Invasion of Russia, with Russia keeping Bessarabia and the Ottomans regaining Wallachia and Moldavia. In the post-Napoleonic world, at the 1815 Congress of Vienna, the Ottoman Empire was still recognized as an essential part of the European status quo.