Melatonin exhibits potential for pain relief and long‐term safety profile. We examined the analgesic effects of oral melatonin on osteoarthritis (OA) and investigated the underlying mechanism. Using data from a UK primary care database, we conducted a cohort study in individuals with OA to compare the number of oral analgesic prescriptions and the risk of knee/hip replacement between melatonin initiators and hypnotic benzodiazepines (i.e., active comparator) initiators using quantile regression models and Cox‐proportional hazard models, respectively. To elucidate causation, we examined the effects of melatonin on pain behaviors and explored several metabolites that may serve as potential regulatory agents of melatonin in the monoiodoacetate rat model of OA. Using data from another community‐based cohort study, that is, the Xiangya OA Study, we verified the association between the key serum metabolite and incident symptomatic knee OA. Compared with the hypnotic benzodiazepines cohort (n = 8135), the melatonin cohort (n = 813) had significantly fewer subsequent prescriptions of oral analgesics (50th percentile: 5 vs. 7, 75th percentile: 19 vs. 29, and 99th percentile: 140 vs. 162) and experienced a lower risk of knee/hip replacement (hazard ratio = 0.47, 95% Cl: 0.30–0.73) during the follow‐up period. In rats, oral melatonin alleviated pain behaviors and increased serum levels of glycine. There was an inverse association between baseline serum glycine levels and the risk of incident symptomatic knee OA in humans (n = 760). In conclusion, our findings indicate that oral melatonin shows significant potential to be a novel treatment for OA pain. The potential role of glycine in its analgesic mechanism warrants further investigation.