In the ICU, patients with sepsis often develop sepsis-associated encephalopathy (SAE), which affects their prognosis. This study aims to construct a predictive model for the 28-day mortality risk of SAE patients using machine learning (ML) methods. We retrospectively collected clinical data of SAE patients admitted to our hospital's intensive care unit (ICU) from January 2018 to June 2023. The primary outcome was whether the patient died within 28 days. We employed six popular machine learning methods to build the predictive model for the 28-day mortality risk of SAE patients, including logistic regression (LR), Gaussian naive Bayes (GaussianNB), support vector machine (SVM), k-nearest neighbor (kNN), random forest (RF), and extreme gradient boosting (XGBoost). Various evaluation metrics were used to analyze the predictive performance of the models. The SHAP analysis method ranked the importance of features influencing the model's output and provided visual output and explanations for individual samples, meeting the need of clinicians to understand model outputs and personalized predictions. In total, this cohort study enrolled 506 SAE patients, with 243 cases (48.02%) resulting in death within 28 days. Overall, the XGBoost model demonstrated superior and stable performance, with the area under the receiver operating characteristic curve (AUC) for both the training and validation sets being higher than the other models, at 0.986 and 0.848, respectively. The SHAP summary plot revealed important clinical features associated with the risk of mortality within 28 days for SAE patients, with a strong dependence on age, SOFA score, and NEUT. Our study indicates that the XGBoost model has good predictive capability for the short-term prognostic outcomes of SAE patients in the ICU and can assist clinicians in the early identification of high-risk patients and the timely implementation of effective treatment strategies to improve the clinical outcomes of SAE patients.