BackgroundA variety of abnormalities in vitamin D metabolism have been reported in patients with active tuberculosis. However, intervention trials have produced inconsistent results. We hypothesized that genetic and epigenetic changes in the key genes of the vitamin D metabolic pathway may partly explain the differences between studies.MethodsWe performed a case-control study followed by a prospective cohort study. We recruited 122 patients with pulmonary tuberculosis and 118 healthy controls. The serum 25-hydroxyvitamin D and 1,25-dihydroxyvitamin D levels were measured. The methylation of the promoter regions of key genes in the vitamin D metabolic pathway (CYP24A1, CYP27A1, CYP27B1, CYP2R1, and VDR) was detected using the Illumina MiSeq platform. The specific methylation profiles were examined as epigenetic biomarkers. The sensitivity, specificity, and receiver operating characteristic (ROC) curves were used to estimate the predictive value of the biomarkers.ResultsThe baseline serum 25-hydroxyvitamin D and 1,25-dihydroxyvitamin D concentrations in the cases were significantly lower than those in the controls (51.60 ± 27.25 nmol/L vs. 117.50 ± 75.50 nmol/L, Z = − 8.515, P < 0.001; 82.63 ± 51.43 pmol/L vs. 94.02 ± 49.26 pmol/L, Z = − 2.165, P = 0.03). We sequenced 310 CpG sites in five candidate genes. After Bonferroni correction, there were 55 differentially methylated CpG sites between cases and controls; 41.5% were in the CYP27B1 gene, 31.7% were in the CYP24A1 gene, 14.7% were in the VDR gene, and 12.3% were in the CYP27A1 gene. When we designated the CpG sites that remained significant after the Bonferroni correction as the biomarkers, the area under the curve (AUC) for the cumulative methylation was 0.810 (95% CI 0.754–0.866). There was an interaction between CYP27A1 methylation level and 1,25-dihydroxyvitamin D concentration associated with the risk of TB (ORinteraction = 4.11, 95% CI 1.26–13.36, P = 0.019). The serum 1,25-dihydroxyvitamin D concentration at the end of the intensive treatment stage was related to a patient’s prognosis (P = 0.008). There were 23 CpG sites that were individually related to the treatment outcomes, but the relationships were not significant after the Bonferroni correction.ConclusionBoth serum vitamin D concentrations and the methylation levels of key genes in the vitamin D metabolic pathway are related to the risk and prognosis of tuberculosis.Electronic supplementary materialThe online version of this article (10.1186/s13148-018-0552-6) contains supplementary material, which is available to authorized users.