Hypovitaminosis D is highly prevalent in type 2 diabetes. The aim of this study is to determine the serum levels of 25-hydroxyvitamin D [25(OH)D] in type 2 diabetic patients with and without mild cognitive impairment (MCI), and examine the relationship of 25(OH)D and MCI with other clinical factors. One hundred and sixty-five diabetic patients were enrolled in this study. Among whom, 95 patients were considered as MCI [Montreal Cognitive Assessment score (MoCA) < 26] and the other 70 as no MCI (MoCA ≥ 26). Subjects were assessed clinically. Diabetic patients with MCI had a longer duration of DM, fewer years of education, elevated fasting blood glucose (FBG), resistant index (RI) of carotid, and lower levels of 25(OH)D {[17.35 (13.02-25.92) vs 28.00 (19.67-34.30)] ng/ml, P < 0.001}. The MoCA score was positively correlated with log10[25(OH)D], education year, and inversely correlated with duration of DM, history of hypertension, intima-media thickness (IMT), FBG, max-RI, and min-RI. Log10[25(OH)D] was positively correlated with MoCA score, and inversely correlated with IMT, in multivariate regression analysis adjusted for age, sex, and education year, 25(OH)D (β = 0.210, P = 0.003), history of hypertension (β = -0.191, P = 0.007), IMT (β = -0.194, P = 0.007), and FBG (β = -0.157, P = 0.026) independently predicted MoCA score. In conclusion, our results suggest that levels of serum 25(OH)D are inversely associated with the cognitive impairment in diabetic patients. Vitamin D may be a potential protective factor for cognitive impairment in patients with type 2 diabetes.