Background: In children admitted to hospital, rapid, accurate diagnosis of pulmonary tuberculosis with the Xpert MTB/RIF assay is possible, but no paediatric studies have been done in the primary care setting, where most children are given care, and where microbiological diagnosis is rarely available. We assessed the diagnostic accuracy of Xpert MTB/RIF in children in primary care. Methods: For this prospective study, we obtained repeat induced sputum and nasopharyngeal aspirate specimens from children (<15 years) with suspected pulmonary tuberculosis at a clinic in Khayeliwtsha, Cape Town, South Africa. We compared the diagnostic accuracy of Xpert MTB/RIF with a reference standard of culture and smear microscopy on induced sputum specimens. For the main analysis, specificity of Xpert MTB/RIF versus liquid culture, we included only children with two interpretable Xpert MTB/RIF and induced sputum culture results. Findings: Between Aug 1, 2010, and July 30, 2012, we enrolled 384 children (median age 38·3 months, IQR 21·2-56·5) who had one paired induced sputum and nasopharyngeal specimen, 309 (81%) of whom had two paired specimens. Five children (1%) tested positive for tuberculosis by smear microscopy, 26 (7%) tested positive by Xpert MTB/RIF, and 30 (8%) tested positive by culture. Xpert MTB/RIF on two induced sputum specimens detected 16 of 28 culture-confirmed cases (sensitivity of 57·1%, 95% CI 39·1-73·5) and on two nasopharyngeal aspirates detected 11 of 28 culture-confirmed cases (sensitivity of 39·3, 23·6-57·6; p=0·18). The specificity of Xpert MTB/RIF on induced sputum was 98·9% (95% CI 96·9-99·6) and on nasopharyngeal aspirates was 99·3% (97·4-99·8). Interpretation: Our findings suggest that Xpert MTB/RIF on respiratory secretions is a useful test for rapid diagnosis of paediatric pulmonary tuberculosis in primary care. Funding: National Institutes of Health, National Health Laboratory Services Research Trust, the Medical Research Council of South Africa, the National Research Foundation South Africa, the European and Developing Countries Clinical Trials Partnership.