From Wikipedia, as usual the emphasis is mine:
and an amusing list of links from that page related to a "Tribalism Mentality" (it looks as if an academic did the first 3, a multiculturalist did 4-9, and a conservative "racist" made the last 4).
Tribalism has a very adaptive effect in human evolution. Humans are social animals, and ill-equipped to live on their own. Tribalism and ethnocentrism help to keep individuals committed to the group, even when personal relations may fray. This keeps individuals from wandering off.
Thus, ethnocentric individuals would have a higher survival rate -- or at least, with their higher commitment to the group, more opportunities to breed. A more significant vector may be that groups with a strong sense of unity and identity can benefit from kin selection behavior such as common property and shared resources. The tendency of members to unite against an outside tribe and the ability to act violently and prejudicially against that outside tribe likely boosted the chances of survival in genocidal conflicts. Logically, a distinct divide between one's own group and other groups fosters the ability of the individual to interact with members of those groups in a manner that is equally distinct: one being altruistic (in the case of a group of unrelated members) or kin-selective (in the case of a group of more or less related members), the other being violent.While it may be tempting to believe that racial conflict, ethnic cleansing, and genocide are the result of increased social pressures from relatively recent societal paradigms such as nations and empires, our understanding of early human history suggests otherwise. Acts of genocide are described in the Judeo-Christian Old Testament (Deut7:2), which is one of the earliest historical works, and clearly involving a state-level society.