Gunther is the son of King Dancrat and Eldest King of the Burgundians. Hagen is the son of Adrian who is the chief vassal of the Burgundian kings. This gives Gunther and Hagen a bond of loyalty, with Hagen being devoted to the service of Gunther and the Burgudian kingdom [vassal: one who is given land by a feudal king etc, who receives the protection of the lord in return for their homage and allegiance (American Heritage Dictionary)]. Hagen's title is Lord of Troneck.
Gunther wins the hand of Brunhild, the Queen of Iceland, through the trickery of Siegfried who manipulates Brunhild into her marriage to Gunther and causes the major conflict of the epic. Hagen aids Gunther in his last stand against Kriemhild, Siegfried's widow, in Etzel the Hun's Hall as Kriemhild seeks her brother Gunther's life for his part in the plot resulting in Siegfried's death.
Gunther and Siegfried were friends because he grew up in Siegfried's kingdom of the Netherlands. Hagen was actually responsible for Siegfried's death because he promised Brunhild to avenge her honor after Kriemhild disclosed what Siegfried did with his magic cloak. Hagen tries to warn Gunther from traveling to Etzels' kingdom in Hungary where the bereaved Kiemhild has taken refuge with Etzel. During the fighting in Hungary between Gunther's Burgundians and Kriemhild's and Etzel's Hungarians, Gunther and Hagen are captured together by Dietrich while Hagen is helping Gunther defend himself.
In the end, Kriemhild uses Siegfried's sword Balmung to slay Hagen for his murder of Siegfried. Her revenge against Gunther and Hagen is ironic and tragic because she is Gunther's sister and Hagen is Gunther's devoted vassal.