Nontuberculous mycobacteria (NTM) infection diagnosis remains a challenge due to its overlapping clinical symptoms with tuberculosis (TB), leading to inappropriate treatment. Herein, we employed noninvasive metabolic phenotyping coupled with comprehensive statistical modeling to discover potential biomarkers for the differential diagnosis of NTM infection versus TB. Urine samples from 19 NTM and 35 TB patients were collected, and untargeted metabolomics was performed using rapid liquid chromatography-mass spectrometry. The urine metabolome was analyzed using a combination of univariate and multivariate statistical approaches, incorporating machine learning. Univariate analysis revealed significant alterations in amino acids, especially tryptophan metabolism, in NTM infection compared to TB. Specifically, NTM infection was associated with upregulated levels of methionine but downregulated levels of glutarate, valine, 3-hydroxyanthranilate, and tryptophan. Five machine learning models were used to classify NTM and TB. Notably, the random forest model demonstrated excellent performance [area under the receiver operating characteristic (ROC) curve greater than 0.8] in distinguishing NTM from TB. Six potential biomarkers for NTM infection diagnosis, including methionine, valine, glutarate, 3-hydroxyanthranilate, corticosterone, and indole-3-carboxyaldehyde, were revealed from univariate ROC analysis and machine learning models. Altogether, our study suggested new noninvasive biomarkers and laid a foundation for applying machine learning to NTM differential diagnosis.