BACKGROUND: The etiology of type 2 diabetes mellitus (T2DM) is complex, with environmental factors playing a significant role in its pathophysiology. Nonsteroidal anti-inflammatory drugs usage and OBJECTIVES: Using a population-based cohort study conducted in Taiwan, we investigated the impact of PUD and anti-PUD medications on the risk of T2DM. DESIGN: This is a retrospective, population-based cohort study using the largest database used in Taiwan. METHODS: An 18-year follow-up period study was conducted on a cohort of patients with PUD diagnosed between 2001 and 2018 using the Taiwan National Health Insurance Research Database. The risk of PUD as well as anti-PUD medications use were examined using Cox proportional regression model. RESULTS: Based on multivariable Cox proportional hazards regression analysis, patients with PUD had a higher overall T2DM incidence (22.7 vs 21.3 per 1000 person-years) than patients without PUD. The adjusted hazard ratio was 1.12 (95% confidence interval = 1.10, 1.13). Patients with PUD have a higher risk of T2DM in both genders and age groups. Patients with anti-PUD medications, such as H2 receptor antagonists, proton-pump inhibitors, antibiotics, prostaglandin analogs, anticholinergics, and antacids usage, are associated with a lower risk of developing T2DM than those without. Patients with PUD who underwent surgery were found to have a higher risk of T2DM. CONCLUSION: Patients with PUD are more likely to develop T2DM. Nevertheless, patients receiving anti-PUD medications have a lower incidence of T2DM.