The spectral theory on the S-spectrum was introduced to give an appropriate mathematical setting to quaternionic quantum mechanics, but it was soon realized that there were different applications of this theory, for example, to fractional heat diffusion and to the spectral theory for the Dirac operator on manifolds. In this seminal paper we introduce the harmonic functional calculus based on the S-spectrum and on an integral representation of axially harmonic functions. This calculus can be seen as a bridge between harmonic analysis and the spectral theory. The resolvent operator of the harmonic functional calculus is the commutative version of the pseudo S-resolvent operator. This new calculus also appears, in a natural way, in the product rule for the F-functional calculus.