As with all emotions, there will be a selection advantage for becoming angry. For instance ever seen animals in the wild fighting over a mate? This sort of anger ensures that you pass on your genes to the next generation at the expense of another animal. Obviously, anger isn’t quite so basic in humans, but I imagine that is where this emotion would have originated from.
As Jemma says it is an emotion that encourages us to protect those we care about especially the young which will protect the next generation and hence the species as a whole. In humans, and likely other animals, it can get out of hand but it is an element of the need for survival.