During magnetic resonance imaging (MRI), a patient’s vital signs are required for different purposes. In cardiac MRI (CMR), an electrocardiogram (ECG) of the patient is required for triggering the image acquisition process. However, a reliable QRS detection of an ECG signal acquired inside an MRI scanner is a challenging task due to the magnetohydrodynamic (MHD) effect which interferes with the ECG. The aim of this work was to develop a reliable QRS detector usable inside the MRI which also fulfills the standards for medical devices (IEC 60601-2-27). Therefore, a novel real-time QRS detector based on integrated variance measurements is presented. The algorithm was trained on ANSI/AAMI EC13 test waveforms and was then applied to two databases with 12-lead ECG signals recorded inside and outside an MRI scanner. Reliable results for both databases were achieved for the ECG signals recorded inside (DBMRI: sensitivity Se = 99.94%, positive predictive value +P = 99.84%) and outside (DBInCarT: Se = 99.29%, +P = 99.72%) the MRI. Due to the accurate R-peak detection in real-time this can be used for monitoring and triggering in MRI exams.