Rapid and accurate detection of pathogenic bacteria is crucial for ensuring food safety and public health. In this study, we aimed to develop a novel molecularly imprinted polymer sensor based on screen-printed electrodes for the specific detection of Salmonella typhimurium. The sensor was constructed by electropolymerizing dopamine in the presence of Salmonella typhimurium on the electrode surface, followed by the removal of the bacteria to create specific binding cavities. The sensor demonstrated excellent specificity for Salmonella typhimurium, with a detection limit approximately of 101 CFU/ml and a detection time of only 4 min, with the sensor accurately differentiating Salmonella typhimurium from other common foodborne pathogens such as Escherichia coli and Listeria monocytogenes. The performance of the sensor was validated using real food samples, including pork and milk, showing its well suited for rapid and on-site detection of pathogenic bacteria. The development of this molecularly imprinted polymer with electrochemical sensor represents a significant advancement in the field of electrochemical biosensors, offering a promising tool for food safety monitoring and public health protection.