Inflammatory bowel disease (IBD) and irritable bowel syndrome (IBS) show a large overlap in clinical presentation, which presents diagnostic challenges. As a consequence, invasive and burdensome endoscopies are often used to distinguish between IBD and IBS. Here, we aimed to develop a noninvasive fecal test that can distinguish between IBD and IBS and reduce the number of endoscopies.We used shotgun metagenomic sequencing to analyze the composition and function of gut microbiota of 169 IBS patients, 447 IBD patients and 1044 population controls and measured fecal Calprotectin (FCal), human beta defensin 2 (HBD2), and chromogranin A (CgA) in these samples. These measurements were used to construct training sets (75% of data) for logistic regression and machine learning models to differentiate IBS from IBD and inactive from active IBD. The results were replicated on test sets (remaining 25% of the data) and microbiome data obtained using 16S sequencing.Fecal HBD2 showed high sensitivity and specificity for differentiating between IBD and IBS (sensitivity = 0.89, specificity = 0.76), while the inclusion of microbiome data with biomarkers (HBD2 and FCal) showed a potential for improvement in predictive power (optimal sensitivity = 0.87, specificity = 0.93). Shotgun sequencing-based models produced comparable results using 16S-sequencing data. HBD2 and FCal were found to have predictive power for IBD disease activity (AUC ≈ 0.7).HBD2 is a novel biomarker for IBD in patients with gastro-intestinal complaints, especially when used in combination with FCal and potentially in combination with gut microbiome data.