An implantable medical device (IMD) including a power supply, a sensing device and/or a stimulation device, a control unit, a magnetic resonance (MR) detection unit, and at least two magnetic field sensors. The power supply is connected to one or more of the sensing device, the stimulation device, the control unit, the MR detection unit and the magnetic field sensors. The control unit is connected to the sensing device and/or stimulation device, to the MR detection unit, and to the at least two magnetic field sensors. The at least two magnetic field sensors are arranged spatially separately from one another and the MR detection unit determines a spatial and/or temporal gradient of magnetic field strengths detected by the at least two magnetic field sensors and transmitted to the MR detection unit. The MR detection unit detects an MR field and transmits an MR signal to the control unit.