This study aimed to clarify the association of the risk of atrial fibrillation (AF) with bowel preparation and subsequent colonoscopy through population-based case-crossover analysis. Patients who developed new-onset AF after undergoing colonoscopy following bowel preparation were included. For each patient, one hazard period and four control periods were matched at specified time windows. Among 189,613 patients with AF, 84 patients (mean age: 72.4 years) finally met the inclusion criteria. Most patients used polyethylene glycol (PEG)-based solutions (2 L PEG + ascorbic acid (n = 56), 4 L PEG (n = 21)) as purgatives and had hypertension (n = 75). A significant association of bowel preparation and colonoscopy with AF occurrence was found in all time windows. The proportion of patients with bowel preparation and colonoscopy was higher during the hazard period than during the control periods. In the 1-, 2-, 4-, 8-, and 12-week time windows, the proportions were 11.9% vs. 4.2%, 13.1% vs. 4.8%, 16.7% vs. 6.3%, 28.6% vs. 11.9%, and 29.8% vs. 14.0%, and the odd ratios (ORs) were 3.11, 3.01, 3.00, 2.96, and 2.61, respectively. Bowel preparation and undergoing colonoscopy was associated with the risk of AF and this examination need to be performed with caution especially in elderly patients with hypertension.