By using the third-harmonic signal generated at an air-dielectric interface, we demonstrate a novel way of correcting wavefront aberrations induced by high-numerical-aperture optics. The third harmonic is used as the input physical parameter of a genetic algorithm working in closed loop with a 37-actuator deformable mirror. This method is simple and reliable and can be used to correct aberrations of tightly focused beams, a regime where other methods have limitations. Improvement of the third-harmonic signal generated with an f/1.2 parabolic mirror by 1 order of magnitude is demonstrated.