This study demonstrates the ability of an electrochemical sensor based on molecularly imprinted polymers (MIPs) to selectively quantify 3,4-methylenedioxymethamphetamine (MDMA), also known as ecstasy, in biological samples. The device was constructed using ortho-phenylenediamine (o-PD) as the MIP's building monomer at the surface of a screen-printed carbon electrode (SPCE). The step-by-step construction of the SPCE-MIP sensor was characterized by cyclic voltammetry (CV) and electrochemical impedance spectroscopy (EIS). Density functional theory (DFT) calculations and modelling were performed not only to understand templatemonomer interaction but also to comprehend which possible polymer structure -linear or ramified poly(o-PD)indeed interacts with the analyte. The prepared sensor worked by directly measuring the MDMA oxidation signal through square-wave voltammetry (SWV) after an incubation period of 10 min. Several parameters were optimized, such as the monomer/template ratio, the number of electropolymerization scanning cycles, and the incubation period, to obtain the best sensing efficiency. Optimized sensors exhibited suitable selectivity, repeatability (2.6%), reproducibility (7.7%) and up to one month of stable response. A linear range up to 0.2 mmol L −1 was found with an r 2 of 0.9990 and a limit of detection (LOD) and quantification (LOQ) of 0.79 and 2.6 μmol L −1 (0.15 and 0.51 μg mL −1 ), respectively. The proposed sensor was successfully applied to human blood serum and urine samples, showing its potential for application in medicine and in forensic sciences.