Liver fibrosis (LF) is a common complication of diabetes mellitus (DM). Studies have found that vitamin D (VD), as a modifiable factor has been reported to be associated with LF. The relationship between serum VD concentration and LF in DM patients has rarely been reported. The aim of this study was to assess the association between serum VD concentration and LF in DM patients. In this cross-sectional study, data of DM patients aged ≥ 45years were extracted from the National Health and Nutrition Examination Survey (NHANES 2017-2018). Serum VD concentration was measured by high performance liquid chromatography-tandem mass spectrometry (HPLC-MS/MS). Vibration controlled transient elastography (VCTE) was used to measure liver stiffness. Covariates included sociodemographic information, lifestyles, laboratory data, diseases history were extracted from the database. The weighted univariable and multivariable logistic regression models were utilized to explore the association between serum VD concentration and LF in DM patients, and were described as odds ratio (ORs) and 95% confidence intervals (CIs). Subgroup analyses based on BMI, liver steatosis, hypertension and dyslipidemia were further assessed the association. A total of 799 patients were included, of which 188 (23.53%) had LF. Higher serum VD concentration was associated with the lower odds of LF (OR = 0.33, 95% CI 0.19-0.59) and advanced LF (OR = 0.31, 95% CI 0.17-0.55) in DM patients after adjustment for race, liver steatosis, BMI, smoking, drinking, AST, ALT and physical activity, especially in patients with liver steatosis (OR = 0.28, 95% CI 0.13-0.59) and dyslipidemia (OR = 0.31, 95% CI 0.14-0.66), respectively. High serum VD concentration may have a potential benefit for maintain the liver health in DM patients.