Background: In South Africa, sputum smear microscopy has been replaced with Xpert MTB/RIF as the initial diagnostic test for tuberculosis. In a pragmatic parallel cluster-randomised trial, we evaluated the effect on patient and programme outcomes. Methods: We randomly allocated 20 laboratories (clusters) in medium-burden districts of South Africa to either an Xpert (immediate Xpert) or microscopy (Xpert deferred) group (1:1), stratified by province. At two primary care clinics per laboratory, a systematic sample of adults giving sputum for tuberculosis investigation was assessed for eligibility. The primary outcome was mortality at 6 months from enrolment. Masking of participants' group allocation was not possible because of the pragmatic trial design. The trial is registered with the ISRCTN registry (ISRCTN68905568) and the South African Clinical Trial Register (DOH-27-1011-3849). Findings: Between June and November, 2012, 4972 people were screened, and 4656 (93·6%) enrolled (median age 36 years; 2891 [62%] female 2212 [62%] reported being HIV-positive). There was no difference between the Xpert and microscopy groups with respect to mortality at 6 months (91/2324 [3·9%] vs 116/2332 [5·0%], respectively; adjusted risk ratio [aRR] 1·10, 95% CI 0·75-1·62]). Interpretation: Xpert did not reduce mortality at 6 months compared with sputum microscopy. Improving outcomes in drug-sensitive tuberculosis programmes might require not only better diagnostic tests but also better linkage to care. Funding: Bill & Melinda Gates Foundation.