Daniel Kriegman in Quillette:
Altruistic behavior toward one’s offspring or other kin is not terribly puzzling since they are genetically related. More puzzling was the development of altruistic behavior toward unrelated others, which does appear to be antithetical to the basic, self-serving fitness interest that underlies evolutionary theory. However, Robert Trivers, in what quickly came to be considered a classic paper, developed the concept of “reciprocal altruism” which sought to explain the adaptive advantage of altruistic behavior toward unrelated others. He was even able to explain altruistic acts between members of different species which, of course, is an extreme example of a lack of genetic relatedness.
Trivers’s concept of reciprocal altruism is based on the notion that an altruistic act can at some point be returned.
More here.