Since you asked a vague question, I will provide a relatively vague answer.
A standard way to test fairness experimentally, is by having people play the ultimatum game. This is an interaction between two participants, one is randomly assigned to be Alice and the other is Bob. Alice is given a couple of days wage in money (either the local currency or other common units of exchange like tobacco) and can decide what proportion of it to offer to Bob. She can choose to offer as little or as much as she wants. Bob is then told what proportion Alice offered and can decide to accept or reject. If Bob accepts then the game ends and each party receives their fraction of the goods. If Bob declines then both Alice and Bob receive nothing and the game terminates. The interaction is completely anonymous and happens only once. In this setting, homoeconomicus would give the lowest possible offer if playing as Alice and accept any non-zero offer as Bob (any money is better than no money).
Henrich et al. (2001) studied the behavior of people from 15 small-scale societies in the ultimatum game and showed a great variability in how fairness is conceived across the societies they studied. None of the small scale societies behaved in the same way as economists would predict (i.e., take everything), and none behaved the way western university student do (western university students tend to offer around 50% and reject offers below 20% about 40% to 60% of the time).
Read more: Games, culture, and the Turing test (Part II)
Related questions: What are popular rationalist responses to Tversky & Shafir? and Human behaviour in one-shot perfect information games
To restate in other words, in such settings it is in our objective self-interest (homoeconomicus) to be unfair, but our subjective conceptions (shaped by evolutionary and cultural forces) entice us to act prosocially. A lot of times this seeming irrationality can be explained as evolutionarily adaptive if we consider concepts like inclusive fitness or group selection.
Read more: Evolving useful delusions to promote cooperation.
Overall, it is an ongoing research question to understand why and to what extent humans and various other organisms cooperate in such games and how this relates to evolution. It is usually studied under the banner of evolution of cooperation. For an introduction that highlights some of the common themes see Nowak (2006), West et al. (2007), or for a video/blog form: Introduction to evolving cooperation.
For a focus on ethnocentrism (one of the highlighted mechanisms) see this question: Do people like those who are similar to them and why?
References
Henrich, J., Boyd, R., Bowles, S., Camerer, C., Fehr, E., Gintis, H., & McElreath, R. (2001). In Search of Homo Economicus: Behavioral Experiments in 15 Small-Scale Societies. American Economic Review, 91(2), 73-78
Nowak MA (2006). Five rules for the evolution of cooperation. Science, 314 (5805), 1560-3.
West, S. A., Griffin, A. S., & Gardner, A. (2007). Evolutionary explanations for cooperation. Current Biology, 17(16), R661-R672.