And because people derive personal esteem and meaning from their group memberships, they are naturally inclined to evaluate their ingroups positively in comparison to outgroups. When an ingroup’s dominant social position is secure or not contested by lower-status outgroups, intergroup harmony is expected to prevail. But when perceived as illegitimate and/or challenged by other groups, ingroup members can be expected to defend their group’s social position by engaging in pro-ingroup and/or anti-outgroup behaviors.
Source: wiktionary