The inhibitory performance of imidazole [1,2-a] pyrimidine derivatives, namely, 2,4-diphenylbenzo [4,5]imidazo [1,2-a]pyrimidine (DPIP) and 2-(4-octylphenyl)-4-phenylbenzo [4,5]imidazo [1,2-a]pyrimidine (OPIP), against mild steel corrosion in 1 mol L−1 HCl solution was studied by weight loss at different temperatures, potentiodynamic polarization curves (PDP), electrochemical impedance spectroscopy (EIS), and surface analysis technology. The two corrosion inhibitors showed an outstanding inhibition performance, and the inhibition efficiency achieved 91.9% for OPIP and 90.5% for DPIP at a concentration of 0.1 mmol L−1. Electrochemical methods showed that DPIP and OPIP behaved as mixed-type inhibitors. Density function theory (DFT) and molecular dynamic simulation (MD) were approached to theoretically study the relationship of the inhibitor structure and anti-corrosion performance, which were also compatible with the weight loss and electrochemical observations.