In the War of the Third Coalition against the French he became a sharpshooter and later a militia captain in the Austrian Imperial and Royal Army. After the Austrian defeat, Tyrol was transferred to the Kingdom of Bavaria (France's ally) according to the 1805 Treaty of Pressburg. During the stern measures of Minister Maximilian von Montgelas and the forced recruitment into the Bavarian Army, Hofer became a leader of the anti-Bavarian movement.