Background Current clinical tests for mycobacterial pulmonary diseases (MPD), such as pulmonary tuberculosis (PTB) and non-tuberculous mycobacteria pulmonary diseases (NTM-PD), are inaccurate, time-consuming, sputum-dependent, and/or costly. We aimed to develop a simple, rapid and accurate breath test for screening and differential diagnosis of MPD patients in clinical settings. Methods Exhaled breath samples were collected from 142 PTB, 68 NTM-PD and 9 PTB&NTM-PD patients, 93 patients with other pulmonary diseases (OPD) and 181 healthy controls (HC), and tested using the online high-pressure photon ionisation time-of-flight mass spectrometer (HPPI-TOF-MS). Machine learning models were trained and blindly tested for the detection of MPD, PTB, NTM-PD, and the discrimination between PTB and NTM-PD, respectively. Diagnostic performance was evaluated by metrics of sensitivity, specificity, accuracy, and area under the receiver operating characteristic curve (AUC). Results The breath PTB detection model achieved a sensitivity of 81.8%, a specificity of 94.3%, an accuracy of 90.7%, and an AUC of 0.957 in the blinded test set (n=150). The corresponding metrics for the NTM-PD detection model were 95.5%, 86.7%, 88.0% and 0.947, respectively. For distinguishing PTB from NTM-PD, the model also achieved good performance with sensitivity, specificity, accuracy, and AUC of 95.5%, 90.9%, 93.9% and 0.974, respectively. 24 potential breath biomarkers associated with MPD were putatively identified and discussed, which included 2-picoline, ethanol, 1-Pentene, etc. Conclusions The developed breathomics-based MPD detection method was demonstrated for the first time with good performance for potential screening and diagnosis of PTB and NTM-PD using a refined operating procedure on the HPPI-TOF-MS platform.