Hirschi, a former under-23 road race world champion, got away away from the peloton in the first major ascent of the 153-kilometer trek in high mountains then resisted the favorites' chase until he was caught with two kilometers left.
Hirschi launched a sprint to the finish line but was not fast enough as Tadej Pogacar prevailed to win the stage ahead of Roglic. Hirschi finished third in the town of Laruns.
Ahead of Monday's first rest day, Roglic dethroned overnight leader Adam Yates thanks to the bonus time he amassed at the top of the final climb and on the finish line.
The 22-year-old Hirschi crossed first at the summit of the Cold de la Hourcere with a lead of 1:35 and went all out on the slippery roads of the technical and perilous downhill that followed. Pedalling while crouched on top of his bike frame and taking aggressive lines through the turns, Hirschi increased his lead and tackled the ascent of the final climb, the Col de Marie Blanque, with a four-minute lead over the chasing group of main contenders.
As the battle between the top riders came alive in the monster climb, Hirschi saw his lead vanish in the thin air but fought until the very end.