Background: Delirium affects up to 50% of patients following high-risk surgeries and is associated with poor long-term prognosis. This study employed machine learning to predict delirium using polysomnography (PSG) and sleep-disorder questionnaire data, and aimed to identify key sleep-related factors for improved interventions and patient outcomes. Methods: We studied 912 adults who underwent surgery under general anesthesia at a tertiary hospital (2013-2024) and had PSG within 5 years of surgery. Delirium was assessed via clinical diagnoses, antipsychotic prescriptions, and psychiatric consultations within 14 days postoperatively. Sleep-related data were collected using PSG and questionnaires. Machine learning predictions were performed to identify postoperative delirium, focusing on model accuracy and feature importance. Results: This study divided the 912 patients into an internal training set (700) and an external test set (212). Univariate analysis identified significant delirium risk factors: midazolam use, prolonged surgery duration, and hypoalbuminemia. Sleep-related variables such as fewer rapid eye movement (REM) episodes and higher daytime sleepiness were also linked to delirium. An extreme gradient-boosting-based classification task achieved an AUC of 0.81 with clinical variables, 0.60 with PSG data alone, and 0.84 with both, demonstrating the added value of PSG data. Analysis of Shapley additive explanations values highlighted important predictors: surgery duration, age, midazolam use, PSG-derived oxygen saturation nadir, periodic limb movement index, and REM episodes, demonstrating the relationship between sleep patterns and the risk of delirium. Conclusions: The artificial intelligence model integrates clinical and sleep variables and reliably identifies postoperative delirium, demonstrating that sleep-related factors contribute to its identification. Predicting patients at high risk of developing postoperative delirium and closely monitoring them could reduce the costs and complications associated with delirium.