This functional magnetic resonance imaging study examined the neural correlates of punishment and forgiveness of initiators of social exclusion (i.e. 'excluders'). Participants divided money in a modified Dictator Game between themselves and people who previously either included or excluded them during a virtual ball-tossing game (Cyberball). Participants selectively punished the excluders by decreasing their outcomes; even when this required participants to give up monetary rewards. Punishment of excluders was associated with increased activation in the pre-supplementary motor area (pre-SMA) and bilateral anterior insula. Costly punishment was accompanied by higher activity in the pre-SMA compared with punishment that resulted in gains or was non-costly. Refraining from punishment (i.e. forgiveness) was associated with self-reported perspective-taking and increased activation in the bilateral temporoparietal junction, dorsomedial prefrontal cortex, dorsal anterior cingulate cortex, and ventrolateral and dorsolateral prefrontal cortex. These findings show that social exclusion can result in punishment as well as forgiveness of excluders and that separable neural networks implicated in social cognition and cognitive control are recruited when people choose either to punish or to forgive those who excluded them.