This study aimed to investigate the relationship between the Dietary Inflammatory Index (DII) and stroke prevalence in patients with diabetes. Data were collected from 9,914 diabetic patients who participated in the National Health and Nutrition Examination Survey (NHANES) between 1999 and 2020. Weighted multivariable logistic regression models were used to analyze the association between DII and stroke risk in diabetic patients, with restricted cubic spline (RCS) regression employed to test for nonlinear relationships. Subgroup analyses were conducted based on sex, age, race, BMI, smoking, alcohol consumption, hypertension, and coronary heart disease status. After adjusting for confounding factors, individuals in the highest DII quartile had a significantly higher risk of stroke compared to those in the lowest quartile, with an adjusted odds ratio (OR) of 1.78 (95% CI: 1.35,2.36). Additionally, each unit increase in DII was associated with a 13% increase in stroke risk (OR: 1.13, 95% CI: 1.06, 1.20). The RCS curve indicated a linear positive association between DII and stroke risk in diabetic patients. A linear positive association between DII and stroke risk was observed in patients with diabetes. Given the cross-sectional nature of the study, further research is required to establish causality.