Background and aim: Stroke-associated pneumonia (SAP) is a common complication in patients with acute ischemic stroke (AIS). This study explored the potential relationship between serum vitamin D levels and SAP. Methods: This study recruited 863 consecutive AIS patients. In-hospital SAP was defined as a complication that occurred after stroke, during hospitalization, that was confirmed radiographically. Serum vitamin D levels were measured within 24 hrs of admission and the patients were divided into vitamin D sufficient (>50 nmol/L), insufficient (25-50 nmol/L), and deficient (<25 nmol/L) groups. Results: In this study, 102 (11.8%) patients were diagnosed with SAP. Compared to the patients without SAP, patients with SAP had significantly lower vitamin D levels (P = 0.023). The incidence of SAP was significantly higher in patients with vitamin D deficiency than in those with vitamin D insufficiency or sufficiency (21.2% vs 16.2% & 9.5%, P = 0.006). After adjusting for confounders, vitamin D deficiency and insufficiency were independently associated with SAP (OR = 3.034, 95% CI = 1.207-7.625, P = 0.018; OR = 1.921, 95% CI = 1.204-3.066, P = 0.006, respectively). In multiple-adjusted spline regression, vitamin D levels showed a linear association with the risk of SAP (P < 0.001 for linearity). Conclusion: Reduced vitamin D is a potential risk factor of in-hospital SAP, which can help clinicians identify high-risk SAP patients.