Background Diabetes mellitus is associated with increased risk of stroke in patients with atrial fibrillation, and differences in glycemic status may affect this risk. We aimed to examine the effect of glycemic status evaluated by hemoglobin A1c (HbA1c) on the risk of thromboembolism among patients with atrial fibrillation and type 2 diabetes mellitus. Methods In this cohort study, we used data from Danish registries to identify patients with type 2 diabetes mellitus and incident nonvalvular atrial fibrillation in the period of May 1, 2005, through December 31, 2015. On the basis of the most recent HbA1c measurement before an incident atrial fibrillation diagnosis, patients were divided into the categories: HbA1c ≤48 mmol/mol, HbA1c=49-58 mmol/mol, and HbA1c >58 mmol/mol. Cox regression analysis was used to estimate hazard ratios for the outcome thromboembolism. Results The study population included 5386 patients with incident nonvalvular atrial fibrillation and type 2 diabetes mellitus. Compared with patients with HbA1c ≤48 mmol/mol, we observed a higher risk of thromboembolism among patients with HbA1c=49-58 mmol/mol (hazard ratio, 1.49; 95% CI, 1.09-2.05) and HbA1c >58 mmol/mol (hazard ratio, 1.59; 95% CI, 1.13-2.22) after adjusting for confounding factors. When stratified on diabetes mellitus duration, similar results were found among patients with diabetes mellitus duration of <10 years. Contrastingly, in patients with diabetes mellitus duration of ≥10 years, higher HbA1c levels were not associated with a higher risk of thromboembolism. Conclusions In patients with incident atrial fibrillation and type 2 diabetes mellitus, increasing levels of HbA1c were associated with a higher risk of thromboembolism. However, no association was found among patients with diabetes mellitus duration ≥10 years.