Desert ants (Cataglyphis) are famous insect navigators. During their foraging lives, the ants leave their underground colonies for long distances and return to their starting point with fair accuracy [1, 2]. Their incessantly running path integrator provides them with a continually updated home vector [3-5]. Directional input to their path integrator is provided by a visual compass based on celestial cues [6, 7]. However, as path integration is prone to cumulative errors, the ants additionally employ landmark guidance routines [8-11]. At the start of their foraging lives, they acquire the necessary landmark information by performing well-structured learning walks [12, 13], including turns about their vertical body axes [14]. When Cataglyphis noda performs these pirouettes, it always gazes at the nest entrance during the longest of several short stopping phases [14]. As the small nest entrance is not visible, the ants can adjust their gaze direction only by reading out their path integrator. However, recent experiments have shown that, for adjusting the goal-centered gaze directions during learning walks, skylight cues are not required [15]. A most promising remaining compass cue is the geomagnetic field, which is used for orientation in one way or the other by a variety of animal species [16-25]. Here, we show that the gaze directions during the look-back-to-the-nest behavior change in a predictable way to alterations of the horizontal component of the magnetic field. This is the first demonstration that, in insects, a geomagnetic compass cue is both necessary and sufficient for accomplishing a well-defined navigational task.