A molecularly imprinted electrochemical sensor was designed for the quantitative and efficient detection of melatonin (MT) based on a Cu x O/MXene modified screen-printed carbon electrode (MIP/Cu x O/MXene/SPCE). Herein, the Cu x O/MXene nanocomposite was prepared via a hydrothermal method. The Cu x O was uniformly dispersed on the surface and the interlayers of the MXene, forming hybrid heterostructures. The encapsulated Cu x O increased the interlayer distance of the MXene matrix to bring more active sites and accelerated the oxidation reaction of melatonin molecules, and thereby the electrochemical response of the sensor was improved. The MIP was constructed by electropolymerization of o-phenylenediamine (o-PD) in the presence of MT on the surface of the Cu x O/MXene/SPCE. The morphology and chemical composition of the hybrid film were characterized by scanning electron microscopy and X-ray photoelectron spectroscopy; the electrochemical behaviors of the sensor were evaluated by cyclic voltammetry and electrochemical impedance spectroscopy. Under the optimal conditions, the MIP/Cu x O/MXene/SPCE sensor had a wide linear detection range of 5−700 μM and a low detection limit of 0.029 μM (S/N = 3) for MT. The sensor also showed excellent selectivity, reproducibility, and stability. Finally, it was successfully applied for MT detection in human urine with satisfactory recovery. Overall, this study provided a sensitive and efficient strategy for the determination of MT.