A method for compensating vertical magnetic anomalies of a magnetometer installed in an aircraft, said magnetometer being associated with the coordinate frame X M, Y M, Z M thereof and the aircraft being associated with the aircraft coordinate frame X A, Y A, Z A thereof, said method, as implemented by a processor of a programmable electronic device, being characterized in that the method includes: - a first step of obtaining first values of compensation coefficients for magnetic anomalies on the magnetometer, the compensation coefficients corresponding to the Euler angles associated with a rotation which changes from the reference coordinate frame of the magnetometer to the aircraft coordinate frame, - a second refining step including the estimation of at least one compensation coefficient for the magnetometer's vertical magnetic anomalies, implemented in a flight phase when the aircraft's attitude departs from the horizontal, the second step comprising: - a) an acquisition of a plurality of values for the magnetic field vectors, as measured by the in-flight magnetometer and of values for associated aircraft attitude angles, - b) a calculation of a magnetic heading as a function the first values for compensation coefficients from the first step and the acquired values for magnetic field vector, - c) a recursive calculation of a coefficient, called the slope coefficient, as a function of a difference in heading between the calculated magnetic heading and a reference magnetic heading, and of values for aircraft attitude angles, - d) a calculation of a value of a compensation coefficient for vertical magnetic anomalies, using a vertical bias estimator, using the calculated slope coefficient, aircraft attitude angle values and characterizing values of the local terrestrial magnetic field. - a first step of obtaining first values of compensation coefficients for magnetic anomalies on the magnetometer, the compensation coefficients corresponding to the Euler angles associated with a rotation which changes from the reference coordinate frame of the magnetometer to the aircraft coordinate frame, - a second refining step including the estimation of at least one compensation coefficient for the magnetometer's vertical magnetic anomalies, implemented in a flight phase when the aircraft's attitude departs from the horizontal, the second step comprising: - a) an acquisition of a plurality of values for the magnetic field vectors, as measured by the in-flight magnetometer and of values for associated aircraft attitude angles, - b) a calculation of a magnetic heading as a function the first values for compensation coefficients from the first step and the acquired values for magnetic field vector, - c) a recursive calculation of a coefficient, called the slope coefficient, as a function of a difference in heading between the calculated magnetic heading and a reference magnetic heading, and of values for aircraft attitude angles, - d) a calculation of a value of a compensation coefficient for vertical magnetic anomalies, using a vertical bias estimator, using the calculated slope coefficient, aircraft attitude angle values and characterizing values of the local terrestrial magnetic field. - a) an acquisition of a plurality of values for the magnetic field vectors, as measured by the in-flight magnetometer and of values for associated aircraft attitude angles, - b) a calculation of a magnetic heading as a function the first values for compensation coefficients from the first step and the acquired values for magnetic field vector, - c) a recursive calculation of a coefficient, called the slope coefficient, as a function of a difference in heading between the calculated magnetic heading and a reference magnetic heading, and of values for aircraft attitude angles, - d) a calculation of a value of a compensation coefficient for vertical magnetic anomalies, using a vertical bias estimator, using the calculated slope coefficient, aircraft attitude angle values and characterizing values of the local terrestrial magnetic field.