Circadian rhythm of melatonin secretion disturbance is common in patients in the intensive care unit (ICU) and may contribute to poor patient prognoses. The aim of this study was to explore the melatonin secretion rhythm in critically ill patients and to identify factors influencing the melatonin secretion rhythm. This was a prospective cohort study conducted in the surgical ICU of a tertiary hospital in Shanghai, China, between February 2022 and December 2022. Patients were enrolled if they were conscious, > 18years, had an expected ICU stay longer than 24 h, and were postoperative. Patient observations started on the first day of admission. ICU light and noise level, baseline characteristics, average night-time interruptions, pain level, use of analgesics and sedation, feeding, duration of mechanical ventilation, leukocyte and procalcitonin (PCT) level, surgical procedures and disease information were observed. We defined melatonin rhythmicity by calculating melatonin acrophase and amplitude. Serum melatonin was collected at 3:00, 8:00, and 16:00 on the first three days after admission. There were 190 ICU patients included in this study. The melatonin acrophase was abnormal in 100 (52.6%) patients. Use of analgesics (p = 0.002) and average night-time interruptions (p = 0.011) were independently related to the melatonin acrophase. Melatonin amplitude was associated with age and average night-time interruptions (p = 0.018 and p = 0.048, respectively). Clinical staff should routinely assess patients' pain levels using validated assessment tools and implement a combination of non-pharmacological and pharmacological pain control interventions. To optimize the ICU environment at night, non-urgent medical procedures should be limited to only those necessary. These approaches may help ICU patients maintain their circadian rhythm and potentially improve their overall recovery.