Negative emotional contagion-witnessing others in distress-affects an individual's emotional responsivity. However, whether it shapes coping strategies when facing future threats remains unknown. We found that mice that briefly observe a conspecific being harmed become resilient, withstanding behavioral despair after an adverse experience. Photometric recordings during negative emotional contagion revealed increased serotonin (5-HT) release in the lateral habenula. Whereas 5-HT and emotional contagion reduced habenular burst firing, limiting 5-HT synthesis prevented burst plasticity. Enhancing raphe-to-habenula 5-HT was sufficient to recapitulate resilience. In contrast, reducing 5-HT release in the habenula made witnessing a conspecific in distress ineffective to promote the resilient phenotype after adversity. These findings reveal that 5-HT supports vicarious emotions and leads to resilience by tuning definite patterns of habenular neuronal activity.