Genetic variation in the μ-opioid receptor gene (OPRM1) is considered one of the contributors to interindividual differences in responses to opioid analgesics in pediatric patients. This study aimed to explore the relationship between OPRM1 polymorphisms and the occurrence of acute postoperative pain across different pediatric age groups. This prospective investigation included 110 children undergoing plastic or orthopedic surgical procedures. Participants were genotyped and then randomly allocated to receive either fentanyl or alfentanil for analgesia. Postoperative pain intensity was assessed using the Numerical Rating Scale (0–10). All enrolled patients were evaluated for the OPRM1 118A > G (rs1799971) genetic polymorphism. In school-aged children younger than 11 years, those with the OPRM1 AA genotype demonstrated a significantly higher body mass index (BMI) (P < 0.05). Among participants older than 12 years, carriers of the OPRM1 G allele exhibited greater postoperative pain sensitivity and intensity than AA genotype carriers (4.91 ± 2.17 vs 3.28 ± 1.95; P < 0.05). The OPRM1 118A > G polymorphism may contribute to differences in postoperative pain perception among children aged 12 years or older. It could serve as a marker to guide individualized analgesic dosing, although dose adjustments should ultimately be based on clinical requirements rather than genotype alone. In younger children, carriers of the OPRM1 118G allele may exhibit a lower risk of obesity, possibly related to reduced μ-opioid receptor (MOP) expression.