According to legend, Erasmus came into conflict with the Habsburgs when he killed the commander of the imperial army, Marshall Pappenheim, who had offended the honour of Erasmus's deceased friend, Andrej Baumkircher of Vipava. Fleeing the vengeance of the Holy Roman Emperor Frederick III, Erasmus reached the family fortress of Predjama. From there, he allied himself with King Matthias Corvinus and began to attack Habsburg estates and towns in Carniola. The emperor commissioned the governor of Trieste, Andrej Ravbar, with the capture or killing of Erasmus. Erasmus was killed after a long siege. According to a popular but unfounded legend, Erasmus was betrayed by one of his men and was killed by a shot from a cannon in his lavatory.