Empathy for pain, the ability to share and understand the pain of others, plays an important role in the survival and development of individuals. Previous studies have found that social pain experience affects empathy for pain, but potential gender differences have not been considered. The stage of information processing during which gender is most likely to play a moderating role has yet to be clarified. In the current study, we set up two groups (social pain experience priming: social exclusion group; positive social interaction experience priming: social inclusion group) with a Cyberball game paradigm. We recorded the electrophysiological responses when participants were completing an empathy task. An early frontal P2 and N2 differentiation between painful stimuli and neutral stimuli was observed and females showed larger P2 amplitudes than males. At the P3 stage, in the social exclusion group, males showed similar parietal P3 amplitudes for painful and neutral stimuli, while females showed smaller P3 amplitudes for painful stimuli. At the central-parietal late positive potential (LPP) stage, females in the social inclusion group showed larger LPP amplitudes for painful stimuli than males. Our results suggest that gender plays a significant moderating role in how social pain experience affects empathy for pain during the late cognitive processing stage. Experiment 2 was designed to investigate the cognitive mechanism behind the results for the P3 component in females and the results partially confirmed our speculation. This study provides a neurophysiological basis for the dynamic gender differences in the effects of social pain experience on empathy for pain.