The combination of electroencephalography (EEG) and functional magnetic resonance imaging (fMRI) allows the investigation of neuronal activity with high temporal and spatial resolution. While much progress has been made to overcome the multiple technical challenges associated with the recording of EEG inside the MR scanner, the ballistocardiographic (BCG) artifact, which is caused by cardiac-related motion inside the magnetic field, remains a major issue affecting EEG quality. The BCG is difficult to remove by standard average artifact subtraction (AAS) methods due to its variability across cardiac cycles. We thus investigate the possibility of directly recording the BCG motion using an optical motion-tracking system. In 5 subjects, the system is shown to accurately measure BCG motion. Regressing out linear and quadratic functions of the measured motion parameters resulted in a significant reduction (p < 0.05) in root-mean-square (RMS) amplitudes across cardiac cycles compared to AAS. A further significant RMS reduction was obtained when applying the regression and AAS methods sequentially, resulting in RMS amplitudes that were not significantly different from those of EEG recorded outside the scanner, although with higher residual variability. The large contributions of pure translational parameters and of non-linear terms to the BCG waveforms indicate that non-rigid motion of the EEG wires (originating from rigid head motion) is likely an important cause of the artifact.