Postoperative delirium is a common complication in patients undergoing elective surgery under general anesthesia. We aimed to minimize the incidence with an oral dose of 3 mg of melatonin administered the night before surgery. Hundred and sixty-two patients aged 40-80 years posted for various urological and gastrointestinal surgeries under general anesthesia with no preoperative cognitive deficits were randomly distributed equally to melatonin or control groups. In the control group, routine premedication was done with tablet alprazolam (0.25 mg) and ranitidine (150 mg), but in the melatonin group, the patients were given 3 mg melatonin orally the night before surgery along with routine premedication. The CAM scale was used for diagnosis of postoperative delirium. Incidence of delirium was significantly lower in the melatonin group, 23.5%, 8.6%, and 2.5% at 6, 24, and 48 hours, respectively, and the corresponding mean (SD) values of CAM scores were 1.37 (1.30), 1.07 (1.03), and 0.69 (0.80). In contrast, the incidence of delirium was 46.9%, 30.9%, and 16% at 6, 24, and 48 hours, respectively, in the control group. There was a significant reduction in anxiety, a lower incidence of cognitive dysfunction (i.e., MoCA score <26), and improvement in sleep quality in the melatonin group at 6, 24, 48, and 72 hours after the surgical intervention. The generalized estimating equations model (GEE) model was used to study change in MoCA and CAM scores over time between the two groups, and it showed a significant interaction between time and treatment groups (P < 0.001). Melatonin premedication reduced incidence of postoperative delirium and cognitive dysfunction and was associated with better sleep quality and anxiolysis.