Empathy for pain is a key driver of prosocial behavior and is influenced by acute psychosocial stress. However, the role of task-based brain connectivity during acute stress have been neglected. Hence, we aimed to explore the relationship between the magnitude of cortisol response to acute stress and empathy for pain, as well as the neural connectivity mechanisms involved. In this study, 80 healthy participants (37 women and 43 men) were exposed to the acute psychosocial stress paradigm (ScanSTRESS) and were scanned by functional magnetic resonance imaging. Saliva samples were collected to measure the magnitude of cortisol stress response. Subsequently, the participants took part in a pain-video task to assess their empathy for pain. Six participants were excluded because of physical discomfort or excessive head movement in all runs during the task-dependent fMRI scan. Therefore, 33 women and 41 men were included in data analysis. We found that empathy for pain was negatively correlated with the magnitude of cortisol stress response (r = -0.268, p = 0.018) and that the task-based connectivity between the salience network and sensorimotor network, including its sub-network and sub-region, was negatively correlated with the magnitude of cortisol stress response, and positively correlated with empathy for pain. Furthermore, task-based connectivity between the insula and the paracentral lobule mediates the effect of the stress-induced cortisol response on empathy for pain (indirect effect = -0.0152, 95% CI = [- 0.036, -0.001], p = 0.036). Our research suggests that empathy is not only correlated with stress-induced glucocorticoids but also tied to the stress-induced reduced communication between basic and higher brain regions.