The Treaty of Gerstungen (German: Frieden von Gerstungen) was concluded on 2 February 1074 in Gerstungen Castle on the River Werra in what is now Germany. It required King Henry IV to restore Duke Otto of Northeim to the Duchy of Bavaria. In 1073 the latter had successfully headed the rebellion of the Saxons. King Henry had to escape from the siege of the Harzburg castle and, under the requirements of the treaty, to accede to the slighting of his castles in the Harz mountains, including for example, the Sachsenburg at Bad Sachsa and only built in 1070.
Since all the South German dukes fought against the re-establishment of the Northeimers, Otto remained deprived of his title in Bavaria. From then Otto was still a dangerous opponent of the king and his former subordinates in Bavaria.