This work introduces for the first time the application of wavelet entropy (WE) to detect episodes of the most common cardiac arrhythmia, atrial fibrillation (AF), automatically from the electrocardiogram (ECG). Given that AF is often asymptomatic and usually presents very brief initial episodes, its early automatic detection is clinically relevant to improve AF treatment and prevent risks for the patients. After discarding noisy TQ intervals from the ECG, the WE has been computed over the median TQ segment obtained from the 10 previous noise-free beats under study. In this way, the P-waves or the fibrillatory waves present in the recording were highlighted or attenuated, respectively, thus enabling the patient's rhythm identification (sinus rhythm or AF). Results provided a discriminant ability of about 95%, which is comparable to previous works. However, in contrast to most of them, which are mainly based on quantifying RR series variability, the proposed algorithm is able to deal with patients under rate-control therapy or with a reduced heart rate variability during AF. Additionally, it also presents interesting properties, such as the lowest delay in detecting AF or sinus rhythm, the ability to detect episodes as brief as five beats in length or its integration facilities under real-time beat-by-beat ECG monitoring systems. Consequently, this tool may help clinicians in the automatic detection of a wide variety of AF episodes, thus gaining further knowledge about the mechanisms initiating this arrhythmia.