We present a model for the evolution of the magnetic properties of habitable terrestrial planets and their effects on the protection of planetary atmosphere against the erosive action of stellar wind. Using up-to-date thermal evolution models and dynamo scaling laws we predict the evolution of the planetary dipole moment as a function of planetary mass and rotation rate. Combining these results with models for the evolution of the stellar wind, stellar XUV fluxes and planetary exosphere characteristics, we determine the properties of the magnetosphere and the exobase radius in order to estimate the level of atmospheric mass losses. We use this model to evaluate the magnetic protection of the potentially habitable super-Earths GJ 667Cc, Gl 581d and HD 85512b. We confirm that Earth-like planets, even under the highest attainable magnetic field strengths, will lose a significant fraction of their atmospheric volatiles if they are tidally locked in the habitable zone of dM stars, or even if having N/O-rich atmospheres they are in habitable zones closer than $\sim$ 0.8 AU. Similar mass-dependent inner limits have been found for super-Earths $M_p\gtrsim 3 M_\oplus$ that in any case seem to have better chances of preserving their atmospheres even if they are tidally locked. We predict that the atmosphere of GJ 667Cc has probably already been obliterated and it is presently uninhabitable. On the other hand, our model predicts that the atmospheres of Gl 581d and HD 85512b would be well protected by intrinsic magnetic fields, even under the worst expected conditions of stellar aggression. (abrigded abstract).