Pyrrolizidine alkaloids are the most widely distributed natural toxins, and pyrrolizidine alkaloid‐containing herbal medicines are probably the most common poisonous plants affecting humans. We reported pyrrolizidine alkaloid‐molecularly imprinted polymer solid‐phase microextraction for the selective adsorption of toxic pyrrolizidine alkaloids from herbal medicine. A sulfonic compound, sodium allylsulfonate, was chosen as the functional monomer to interact with pyrrolizidine alkaloids through strong ionic interaction. To avoid template leakage and for the aim of cost saving, a relatively cheap dummy template was used for the fabrication of molecularly imprinted polymer‐solid‐phase microextraction fibers. The obtained fibers showed selective adsorption ability for four pyrrolizidine alkaloids, including europine, echimidine, lasiocarpine, and heliotrine. The extraction parameters, such as extraction time, extraction temperature, shaking speed, elution solvent and elution time, were optimized. Then ultra high performance liquid chromatography with mass spectrometry coupled with molecularly imprinted polymer‐solid‐phase microextraction method was developed for the fast and efficient analysis of four pyrrolizidine alkaloids from the model herbal plant Farfarae Flos. The established method was validated and exhibited satisfactory accuracy and precision. The present method provides an innovative and fast analytical strategy for the determination of trace toxic pyrrolizidine alkaloids in complicated samples.