The motivation to seek social contact may arise from either positive or negative emotional states, as social interaction can be rewarding and social isolation can be aversive. While ventral tegmental area (VTA) dopamine (DA) neurons may mediate social reward, a cellular substrate for the negative affective state of loneliness has remained elusive. Here, we identify a functional role for DA neurons in the dorsal raphe nucleus (DRN), in which we observe synaptic changes following acute social isolation. DRN DA neurons show increased activity upon social contact following isolation, revealed by in vivo calcium imaging. Optogenetic activation of DRN DA neurons increases social preference but causes place avoidance. Furthermore, these neurons are necessary for promoting rebound sociability following an acute period of isolation. Finally, the degree to which these neurons modulate behavior is predicted by social rank, together supporting a role for DRN dopamine neurons in mediating a loneliness-like state.