An automated method for electrocardiogram (ECG)-artifact detection and elimination is proposed for application to a single-channel electroencephalogram (EEG) without a separate ECG channel for reference. The method is based on three characteristics of ECG artifacts: the spike-like property, the periodicity and the lack of correlation with the EEG. The method involves a two-step process: ECG artifact detection using the energy interval histogram (EIH) method and ECG artifact elimination using a modification of ensemble average subtraction. We applied a smoothed nonlinear energy operator to the contaminated EEG, which significantly emphasized the ECG artifacts compared with the background EEG. The EIH method was initially proposed to estimate the rate of false positives (FPs) and false negatives (FNs) that were necessary to determine the optimal threshold for the detection of the ECG artifact. As a postprocessing step, we used two types of threshold adjusting algorithms that were based on the periodicity of the ECG R-peaks. The technique was applied to four whole-night sleep EEG recordings from four subjects with severe obstructive sleep apnea syndrome, from which a total of 132 878 heartbeats were monitored over 31.8 h. We found that ECG artifacts were successfully detected and eliminated with FP = 0.017 and FN = 0.074 for the epochs where the elimination process is necessarily required.