Background: Vitamin D was used to treat tuberculosis in the pre-antibiotic era, and its metabolites induce antimycobacterial immunity in vitro. Clinical trials investigating the effect of adjunctive vitamin D on sputum culture conversion are absent. Methods: We undertook a multicentre randomised controlled trial of adjunctive vitamin D in adults with sputum smear-positive pulmonary tuberculosis in London, UK. 146 patients were allocated to receive 2·5 mg vitamin D3 or placebo at baseline and 14, 28, and 42 days after starting standard tuberculosis treatment. The primary endpoint was time from initiation of antimicrobial treatment to sputum culture conversion. Patients were genotyped for TaqI and FokI polymorphisms of the vitamin D receptor, and interaction analyses were done to assess the influence of the vitamin D receptor genotype on response to vitamin D3. This trial is registered with ClinicalTrials.gov number NCT00419068. Findings: 126 patients were included in the primary efficacy analysis (62 assigned to intervention, 64 assigned to placebo). Median time to sputum culture conversion was 36·0 days in the intervention group and 43·5 days in the placebo group (adjusted hazard ratio 1·39, 95% CI 0·90–2·16; p=0.14). TaqI genotype modified the effect of vitamin D supplementation on time to sputum culture conversion (pinteraction=0·03), with enhanced response seen only in patients with the tt genotype (8·09, 95% CI 1·36–48·01; p=0·02). FokI genotype did not modify the effect of vitamin D supplementation (pinteraction=0·85). Mean serum 25-hydroxyvitamin D concentration at 56 days was 101·4 nmol/L in the intervention group and 22·8 nmol/L in the placebo group (95% CI for difference 68·6–88·2; p<0·0001). Interpretation: Administration of four doses of 2·5 mg vitamin D3 increased serum 25-hydroxyvitamin D concentrations in patients receiving intensive-phase treatment for pulmonary tuberculosis. Vitamin D did not significantly affect time to sputum culture conversion in the whole study population, but it did significantly hasten sputum culture conversion in participants with the tt genotype of the TaqI vitamin D receptor polymorphism.