Human empathy can extend to strangers and even other species, but it is unknown whether non-humans are similarly broad in their empathic responses. We explored the breadth and flexibility of empathy in chimpanzees, a close relative of humans. We used contagious yawning to measure involuntary empathy and showed chimpanzees videos of familiar humans, unfamiliar humans and gelada baboons (an unfamiliar species). We tested whether each class of stimuli elicited contagion by comparing the effect of yawn and control videos. After including previous data on the response to ingroup and outgroup chimpanzees, we found that familiar and unfamiliar humans elicited contagion equal to that of ingroup chimpanzees. Gelada baboons did not elicit contagion, and the response to them was equal to that of outgroup chimpanzees. However, the chimpanzees watched the outgroup chimpanzee videos more than any other. The combination of high interest and low contagion may stem from hostility towards unfamiliar chimpanzees, which may interfere with an empathic response. Overall, chimpanzees showed flexibility in that they formed an empathic connection with a different species, including unknown members of that species. These results imply that human empathic flexibility is shared with related species.