A crucial feature of socially adaptive behavior is the ability to recognize when our actions harm other individuals. Previous research demonstrates that dorsal mediofrontal cortex (dMFC) and anterior insula (AI) are involved in both action monitoring and empathy for pain. Here, we tested whether these regions could integrate monitoring of error agency with the representation of others' pain. While undergoing event-related fMRI, participants played a visual task in turns with a friend placed outside the scanner, who would receive painful stimulation in half of the error trials. Brain activity was enhanced in dMFC and AI for painful compared with nonpainful errors. Left AI and dorsolateral pFC also exhibited a significant interaction with agency and increased responses when painful errors were caused by oneself. We conclude that AI is crucial for integrating inferences about others' feeling states with information about action agency and outcome, thus generating an affective signal that may guide subsequent adjustment.