BackgroundAlthough diabetes is reportedly associated with the occurrence of acute pancreatitis (AP), the risk of AP according to the duration and severity of diabetes is not yet clear. We aimed to investigate the risk of AP based on glycemic status and the presence of comorbidities using a nationwide population-based study.MethodsWe enrolled 3,912,496 adults who underwent health examinations under the National Health Insurance Service in 2009. All participants were categorized by glycemic status as normoglycemic, impaired fasting glucose (IFG), or diabetes. Baseline characteristics and the presence of comorbidities at the time of health check-up were investigated, and the occurrence of AP was followed up until 31 December 2018. We estimated the adjusted hazard ratios (aHRs) for AP occurrence according to the glycemic status, duration of diabetes (new-onset, duration < 5 years, or ≥ 5 years), type and number of anti-diabetic medications, and presence of comorbidities.ResultsDuring the observation period of 32,116,716.93 person-years, 8,933 cases of AP occurred. Compared with normoglycemia, the aHRs (95% confidence interval) were 1.153 (1.097–1.212) in IFG, 1.389 (1.260–1.531) in new-onset diabetes, 1.634 (1.496–1.785) in known diabetes < 5 years, and 1.656 (1.513–1.813) in patients with known diabetes aged ≥ 5 years. The presence of comorbidities associated with diabetes severity had a synergistic effect on the relationship between diabetes and AP occurrence.ConclusionAs glycemic status worsens, the risk of AP increases, and there is a synergistic effect when comorbidities coexist. To reduce the risk of AP, active control of factors that can cause AP should be considered in patients with long-standing diabetes and comorbidities.Supplementary InformationThe online version contains supplementary material available at 10.1186/s13098-023-01086-x.