Background Distant metastasis (DM) is an important prognostic factor and determines the following treatments in patients with colorectal cancer (CRC). The purpose of this study was to construct prediction models for DM in patients with CRC based on machine learning. Methods CRC patients between 2010 and 2015 from the Surveillance, Epidemiology, and End Results (SEER) database were identified. Prediction models for DM were developed by applying four machine-learning methods including eXtreme Gradient Boost (XGB), decision tree (DT), random forest (RF), and support vector machine (SVM). The performance of models was quantitatively assessed by receiver operating characteristics (ROC) curve, calibration curve and decision curve analysis (DCA) curve. The SHapley Additive exPlanation (SHAP) method was used for visualization analysis to better explain the results of the machine learning models. Results A total of 51788 patients were identified in the SEER database. ROC curves exhibited excellent accuracy of machine learning models. Calibration curves for the probability of DM showed good agreement between model prediction and actual observation in both the training and validation cohorts. The DCA demonstrated that each machine learning model can provide net benefits with treat-none and treat-all strategies. In the SHAP summary plot of the RF and XGB models, carcinoembryonic antigen (CEA), N stage, T stage and tumor deposits were identified as the most important risk factors for DM. Conclusion The XGB and RF were ideal machine learning models and showed that CEA, N stage, T stage and tumor deposits were the most important DM-related risk factors.