A pacemaker comprises an implantable pacemaker housing and a pacemaker electrode which is provided for the transmission of stimulation pulses. A switching element, in particular a reversibly actuatable switching element, is provided for interrupting, reducing or limiting a current flowing through the pacemaker electrode, said current being inducible by an external magnetic field. Parts of the pacemaker are coated with a material, in particular a nanostructured material, which counteracts magnetic effects.