The fortification was built between 1075 and 1078 at the behest of Archbishop Gebhard of Salzburg during the Imperial Investiture Controversy, meant as a strategic bulwark atop a high rock. Gebhard, an ally of Pope Gregory VII and the anti-king Rudolf of Rheinfelden, had three major castles extended to secure the route across the Eastern Alps along the Salzach river against the forces of King Henry IV of Germany: Hohenwerfen, Hohensalzburg and Petersberg Castle at Friesach in Carinthia. Nevertheless, King Henry had Gebhard expelled in 1077 and the archbishop could not return to Salzburg until 1086, only to die at Hohenwerfen two years later.