According to the 1797 Peace of Campo Formio, which concluded the War of the First Coalition, France was to annex the Left Bank of the Rhine and the German princes who lost territory to France were to be compensated with ecclesiastical possessions east of the Rhine. This compensation ballooned into the "Reichsdeputationshauptschluss" of 1802–03, which erased all ecclesiastical states except the Electorate of Mainz, which was moved south to Regensburg, and the Teutonic Knights at Mergentheim, and the Knights Hospitaller at Heitersheim. The ecclesiastical states were to be governed by German nobles, with the Teutonic Knights coming under Austrian control. Just two years later in 1805, at the end of the War of the Third Coalition, the Peace of Pressburg gave Mergentheim fully to Austria. Austrian troops were stationed in the town until 1809, when it was occupied by the Kingdom of Württemberg on 20 April 1809, during the War of the Fifth Coalition. In the process of German mediatization that followed in 1809, Napoleon Bonaparte stripped the Teutonic order of its possessions in what was to become the Confederation of the Rhine. Mergentheim was awarded to Württemberg on 29 May 1809 In the process of annexation, Württemberger authorities looted Mergentheim Palace and moved the seminary's library to Stuttgart, the kingdom's capital.