Purpose: Sodium glucose cotransporter 2 inhibitor (SGLT2i) reduced the risk of hard cardiovascular endpoints in type 2 diabetes mellitus (T2DM) patients with/without established cardiovascular diseases. Whether SGLT2i is associated with a lower risk of new-onset atrial fibrillation (AF) in T2DM patients is unclear. We aimed to evaluate the risk of new-onset AF associated with the use of SGLT2i compared to dipeptidyl peptidase-4 inhibitors (DPP4i) among a longitudinal cohort of diabetic patients. Methods: We used medical data from a multi-center healthcare provider in Taiwan, which included a total of 21,480 and 22,989 patients treated with SGLT2i and DPP4i, respectively, from June 1, 2016 to December 31, 2018. We used propensity-score weighting to balance covariates across study groups. Patients were followed up from the drug index date until the occurrence of new-onset AF, discontinuation of the index drug, or the end of the study period, whichever occurred first. Results: Overall, 56%, 42%, and 2% of the patients were treated with empagliflozin, dapagliflozin, and canagliflozin, respectively. Most patients in the DPP4i group were prescribed with linagliptin (51%), followed by sitagliptin (24%), saxagliptin (13%), vildagliptin (8%) and alogliptin (4%). The use of SGLT2i was associated with a lower risk of new-onset AF compared with DPP4i after propensity-score weighting [adjusted hazard ratio: 0.69; 95% confidential interval: 0.64-0.74; P < 0.001]. Subgroup analysis revealed that the use of SGLT2i was associated with a lower risk of new-onset AF compared with DPP4i across several subgroups including old age, the presence of congestive heart failure, cardiovascular disease, overweight patients, hemoglobin A1c 8%, and chronic kidney disease. The advantage of SGLT2i over DPP4i persisted with different SGLT2i (dapagliflozin or empagliflozin) and either low- or standard-dose SGLT2i. Conclusions: SGLT2i was associated with a lower risk of new-onset AF compared with DPP4i among T2DM patients in real-world practice.