In 1803, it was merged with the Kingdom of Galicia and Lodomeria, but retained some autonomy. It remained a territory of the Austrian Empire even when, in 1807, Napoleon I of France created the Duchy of Warsaw from territories in Greater Poland which Prussia had annexed in the Second and Third Partition and now was forced to renounce according to the Treaty of Tilsit. Austria lost New Galicia in the 1809 War of the Fifth Coalition, after a corps under Archduke Ferdinand Karl Joseph of Austria-Este on 15 April 1809 started the Polish–Austrian War by invading the Duchy of Warsaw. Despite the archduke's plans to move in as a national liberator he was challenged by the forces of Prince Józef Poniatowski at the Battle of Raszyn. Austria was finally defeated at the Battle of Wagram on 6 July, whereafter New Galicia was attached to the Duchy of Warsaw by the Treaty of Schönbrunn.