ObjectivesDiabetes mellitus is a metabolic condition with hyperglycemia. Literature has shown a correlation between poor sleep quality and duration with an increased incidence of insomnia in diabetic individuals. The goal of this study was to determine the magnesium and potassium supplementation effect among diabetic individuals with insomnia.MethodsA randomized controlled trial (single blind) was conducted on 320 patients with diabetes; after 2 months of follow-up, 290 patients completed the trial. The Insomnia Severity Index (ISI) was used to assess the severity and duration of insomnia, before and after the trial. Tablets containing supplements were prepared: placebo (T1), magnesium (Mg, T2), potassium (K, T3), and a combination of Mg and K (T4). Melatonin and cortisol (sleep hormones) were measured from blood (serum) using an enzyme-linked immunosorbent assay (ELISA), before and after the trial.ResultsThe study included 93 (32.1%) male and 197 (67.9%) female participants. According to the analysis, there was a significant association between the treatment groups and ISI after the trial (post-trial), p = 0.0001. Analysis showed that there was significant association between pre- and post-serum cortisol levels in treatment groups 2, 3, and 4 (T2, T3, and T4) as p-values are 0.001, 0.001, and 0.001 respectively. Similar findings were observed for serum melatonin.ConclusionsThe study revealed that magnesium, potassium, and magnesium and potassium combined had a significant effect on serum cortisol and melatonin levels (sleep hormones). In addition, supplementation significantly decreased the severity of insomnia among patients with diabetes by improving sleep duration.