In an era of increasing need for precision medicine, machine learning has shown promise in making accurate acute myocardial infarction outcome predictions. The accurate assessment of high-risk patients is a crucial component of clinical practice. Type 2 diabetes mellitus (T2DM) complicates ST-segment elevation myocardial infarction (STEMI), and currently, there is no practical method for predicting or monitoring patient prognosis. The objective of the study was to compare the ability of machine learning models to predict in-hospital mortality among STEMI patients with T2DM. We compared six machine learning models, including random forest (RF), CatBoost classifier (CatBoost), naive Bayes (NB), extreme gradient boosting (XGBoost), gradient boosting classifier (GBC), and logistic regression (LR), with the Global Registry of Acute Coronary Events (GRACE) risk score. From January 2016 to January 2020, we enrolled patients aged > 18 years with STEMI and T2DM at the Affiliated Hospital of Zunyi Medical University. Overall, 438 patients were enrolled in the study [median age, 62 years; male, 312 (71%); death, 42 (9.5%]). All patients underwent emergency percutaneous coronary intervention (PCI), and 306 patients with STEMI who underwent PCI were enrolled as the training cohort. Six machine learning algorithms were used to establish the best-fit risk model. An additional 132 patients were recruited as a test cohort to validate the model. The ability of the GRACE score and six algorithm models to predict in-hospital mortality was evaluated. Seven models, including the GRACE risk model, showed an area under the curve (AUC) between 0.73 and 0.91. Among all models, with an accuracy of 0.93, AUC of 0.92, precision of 0.79, and F1 value of 0.57, the CatBoost model demonstrated the best predictive performance. A machine learning algorithm, such as the CatBoost model, may prove clinically beneficial and assist clinicians in tailoring precise management of STEMI patients and predicting in-hospital mortality complicated by T2DM.