Melatonin (MEL) modulates the circadian rhythm and has been studied as a preventive measure against delirium, especially in intensive care unit (ICU) patients, but the current findings are conflicting. We performed a pairwise dose‒response meta-analysis of randomized controlled trials (RCTs) followed by meta-regression and trial sequential analysis to assess the ability of MEL or ramelteon (RAL) to prevent delirium in the ICU. We evaluated the certainty of the evidence via GRADE and the credibility of the subgroup analysis via the ICEMAN tool. We identified 24 studies that included 3680 participants. Compared with placebo, melatoninergic agonists reduce the incidence of delirium (0.77 [0.62,0.94], primary analysis of 18 studies), with superior effects in the MEL group (RR 0.77 [0.62, 0.97]) and in surgical-type ICU (RR 0.64 [0.48, 0.87]). We found a nonlinear dose‒response relationship between the cumulative dose of MEL and the RR of delirium, suggesting an optimal cumulative dose of 22 mg of MEL (RR 0.732 [0.599, 0.895]). Subgroup and meta-regression analyses revealed a significant effect of intervention duration on the risk of delirium, with a superior effect in the subgroup with ≥ 7 days of intervention (RR 0.73 [0.60, 0.90]). Melatoninergic agonists did not affect 28-30-day or ICU mortality or the incidence of adverse effects. Melatoninergic agonists showed a clinically relevant trend based on the minimal clinically important difference (MCID) to reduce the ICU length of stay (LOS) (MD:-0.74 [-1.60, 0.12], MCDI -0.113 [1.846, -2.073]), hospital LOS (MD -0.33 [-1.91, 1.25], MCID -0.134 [1.833, -2.108]) and length of mechanical ventilation (MV) (MD -0.50 [-1.16, 0.16], MCID -0.2146 [1.744, -2.173]). Compared with placebo, they may increase the time to the onset of delirium (MD 0.76 [0.43, 1.09]), but with very-low certainty. Our findings indicate that melatoninergic agonists probably reduce the risk of delirium in ICU patients, especially those treated with MEL, in surgical-type ICUs and for durations equal to or longer than 7 days, with an optimal cumulative dose of 22 mg. Additionally, they appear to be safe while offering potential benefits in reducing ICU length of stay and duration of mechanical ventilation. However, the magnitude of effect was modest, with low-certainty evidence and moderate heterogeneity, and these findings should therefore be interpreted with caution.