In a study with squirrel mussel fish, they have been shown to be able to detect the fear of their peers, and when this happens, they get infected with that emotion. And you've seen that the molecule that gives you this ability is oxytocin, a hormone that binds to empathy in humans and other mammals.
The research published in the journal Science explains that this phenomenon involves the same areas, both in the brains of fish and mammals. It follows that the basis of this form of empathy arose many millions of years ago and has persisted in evolution.