In social life, empathy and morality are often viewed as inseparable and mutually reinforcing. Pain empathy is a key form of empathy, and understanding how social moral factors affect pain empathy is an important challenge. This study uses various EEG analysis methods to explore the cognitive and neural mechanisms by which moral enhancement affects pain empathy. Behavioral results showed significantly higher ratings for painful stimuli compared to non-painful ones. ERP analysis revealed that, under moral enhancement, pain stimuli elicited more negative N1 amplitudes and more positive P3 amplitudes. Time-frequency analysis indicated that moral enhancement inhibited theta band activity in response to painful stimuli. Functional connectivity analysis showed stronger connections in the frontal, right temporal, and occipital regions under moral enhancement and in the frontal, right temporal, and parietal regions when viewing painful stimuli. Additionally, machine learning results indicated that functional connections between the right temporal and parietal regions have significant negative predictive power for moral enhancement during painful stimuli. This study reveals the complex effects of moral enhancement on pain-related stimuli, demonstrating that it not only increases adaptability to pain but also enhances moral judgment, offering new insights into the interaction between moral cognition and emotional responses with significant theoretical and practical implications.