Clostridioides difficile infection (CDI) following colorectal surgery can lead to significant adverse outcomes. Although previous studies have identified risk factors for CDI, their relative importance for predicting complications remains unclear. Objective: We sought to use machine-learning algorithms to accurately determine which perioperative risk factors are most predictive of adverse outcomes after CDI. Methods: The National Surgical Quality Improvement Project (NSQIP) database was used to identify all patients who developed CDI after a colorectal operation in 2016 (N = 14,392). We excluded patients without CDI and patients <18 years of age. Any missing data were replaced with multivariate singular value decomposition imputation. We collected data on patient demographics, comorbidities, preoperative laboratory values, operative details, and outcomes, including infectious, cardiovascular, hematologic, renal, and pulmonary complications, unplanned returns to the operating room (RTOR), non–home discharge, readmission, and mortality. Data were univariably assessed for significant association with outcomes. If an input variable significantly correlated with ≥5 outcomes, it was included in our machine-learning models. We utilized bootstrap aggregation with random forests to improve prediction accuracy. We then calculated each input variable’s importance to the model outcome (VIP). The VIPs of each variable were averaged to yield an overall impact. Each model’s accuracy was determined by the area under the receiver operator curve (AUROC). Results: There were 841 patients in our cohort (median age 66 years (IQR, 55–75.8), 482 (57%) were women, and the mean American Society of Anesthesiologists [ASA] class score was 2.9 (SD, ±0.7). Of all colorectal surgeries, 172 (20.5%) were emergent. Overall mortality was 3.8% (n=32), and 371 patients (44.1%) experienced at least 1 postoperative complication, of which infectious complications (eg, septic shock, sepsis, wound infection, urinary tract infection) were most common (n=255, 30.3%). The RTOR rate was 10.3% (n = 87), the non–home discharge rate was 23.8% (n = 200), and the readmission rate was 30.9% (n = 260). The input variables most predictive of any adverse outcome were hematocrit (VIP, 24.9%), ASA class (VIP, 24.4%), creatinine (VIP, 17.4%), and prealbumin (VIP, 11.6%). The probability of any adverse outcome was 90.6% in the setting of hematocrit ≤27%, ASA class ≥3, creatinine ≥1.6 mg/dL, and prealbumin ≤3.1 mg/dL. All machine-learning models had an AUROC ≥0.99. Conclusions: Although nonpatient factors can contribute to unfavorable outcomes in patients with CDI following colorectal surgery, we identified 4 patient-specific variables that account for almost 80% of any adverse outcomes. Although further prospective study is needed, individuals with these preoperative risk factors could consider delaying their elective colorectal operations until they are medically optimized.