Biological competition is widely believed to result in the evolution of selfish preferences. The related concept of the ‘homo economicus’ is at the core of mainstream economics. However, there is also experimental and empirical evidence for other-regarding preferences. Here we present a theory that explains both, self-regarding and other-regarding preferences. Assuming conditions promoting non-cooperative behaviour, we demonstrate that intergenerational migration determines whether evolutionary competition results in a ‘homo economicus’ (showing self-regarding preferences) or a ‘homo socialis’ (having other-regarding preferences). Our model assumes spatially interacting agents playing prisoner's dilemmas, who inherit a trait determining ‘friendliness’, but mutations tend to undermine it. Reproduction is ruled by fitness-based selection without a cultural modification of reproduction rates. Our model calls for a complementary economic theory for ‘networked minds’ (the ‘homo socialis’) and lays the foundations for an evolutionarily grounded theory of other-regarding agents, explaining individually different utility functions as well as conditional cooperation.