BackgroundVitamin D level is inversely associated with tuberculosis (TB) and diabetes (DM). Vitamin D could be a mediator in the association between TB and DM. We examined the associations between vitamin D, TB and DM.MethodsConsecutive adults with TB and sex- and age-matched volunteers were included in a case-control study in Dar es Salaam, Tanzania. Glycemia and total vitamin D (25(OH)D) were measured at enrolment and after TB treatment in cases. The association between low 25(OH)D (<75 nmol/l) and TB was evaluated by logistic regression adjusted for age, sex, body mass index, socioeconomic status, sunshine hours, HIV and an interaction between low 25(OH)D and hyperglycemia.ResultsThe prevalence of low 25(OH)D was similar in TB patients and controls (25.8 % versus 31.0 %; p = 0.22). In the subgroup of patients with persistent hyperglycemia (i.e. likely true diabetic patients), the proportion of patients with low 25(OH)D tended to be greater in TB patients (50 % versus 29.7 %; p = 0.20). The effect modification by persistent hyperglycemia persisted in the multivariate analysis (pinteraction = 0.01).ConclusionsLow 25(OH)D may increase TB risk in patients with underlying DM. Trials should examine if this association is causal and whether adjunct vitamin D therapy is beneficial in this population.Electronic supplementary materialThe online version of this article (doi:10.1186/s12879-016-1960-x) contains supplementary material, which is available to authorized users.