Preoperative knowledge of expected postoperative pain can help guide perioperative pain management and focus interventions on patients with the greatest risk of acute pain. However, current methods for predicting postoperative pain require patient and clinician input or laborious manual chart review and often do not achieve sufficient performance. We use routinely collected electronic health record data from a multicenter dataset of 234,274 adult non-cardiac surgical patients to develop a machine learning method which predicts maximum pain scores on the day of surgery and four subsequent days and validate this method in a prospective cohort. Our method, POPS, is fully automated and relies only on data available prior to surgery, allowing application in all patients scheduled for or considering surgery. Here we report that POPS achieves state-of-the-art performance and outperforms clinician predictions on all postoperative days when predicting maximum pain on the 0–10 NRS in prospective validation, though with degraded calibration. POPS is interpretable, identifying comorbidities that significantly contribute to postoperative pain based on patient-specific context, which can assist clinicians in mitigating cases of acute pain.