STUDY OBJECTIVE: Delirium is a common complication after cardiac surgery and is associated with poor prognosis. An effective delirium prediction model could identify high-risk patients who might benefit from targeted prevention strategies. We introduce machine learning models that employ resting-state functional MRI datasets obtained before surgery to predict postoperative delirium. DESIGN: A secondary analysis of a prospective observational study. SETTING: The study was conducted at one tertiary hospital in China. PATIENTS: The study involved 103 patients who underwent preoperative functional MRI scan and cardiac valve replacement. INTERVENTIONS: None. MEASUREMENTS: Delirium was assessed twice daily for the first seven postoperative days using the Confusion Assessment Method. We used three whole-brain functional connectivity (FC) measures (parcel-wise connectivity matrix, mean FC and degree of FC) and trained three machine models, namely, random forest, logistic regression, and linear support vector machine, to distinguish delirium patients from patients without delirium. The top performing model was selected for further training with functional MRI datasets and clinical variables. MAIN RESULTS: This study included 103 participants. A total of 29 participants (28.2 %) met postoperative delirium criteria. Based solely on functional MRI datasets, the random forest model trained using the degree of FC achieved the highest accuracy (0.864), precision (0.887), specificity (0.894), F1 score (0.859) and area under the curve (0.924), and this model was further optimized for accuracy (0.879), sensitivity (0.909), F1 score (0.882) and area under the curve (0.928) by fusing clinical variables. The most discriminative nodes for predicting postoperative delirium were located in the default, cingulo-opercular, and frontoparietal networks. CONCLUSIONS: This study found that the random forest model using preoperative functional MRI data and clinical variables was accurate in identifying patients at high risk of developing delirium after cardiac surgery.