A tale of revenge is always bittersweet. Take the sack of Troy, as depicted in Homer's epic poem The Iliad. When Paris steals away Helen, her husband King Menelaus cannot bear the injustice and seeks to attack her seducer. He brings an entire army to Troy, waging a lengthy war that kills thousands.

The theme of revenge spirals through the entire narrative. When Achilles' best friend and cousin Patroklus is killed, he too seeks a reckless and bloody revenge.

Revenge has been part of human behaviour for almost as long as we have existed on Earth. Literature has used it throughout history, from Greek tragedies such as Aeschylus' Oresteia trilogy – where Orestes wants to murder his mother to avenge his father – to Shakespeare’s Hamlet.

Many of us have no doubt imagined vengeance against those who have wronged us, or even lashed out at them. In the moment, it can certainly feel cathartic to do so. But what motivates us to seek revenge in the first place? Researchers are gradually getting some answers, and they are finding that revenge has some unexpected upsides.

People from every society understand the idea of getting angry and wanting to hurt someone who has harmed you  

Revenge is a powerful emotional trigger that mobilises people into action. "It's this very pervasive experience in human lives, people from every society understand the idea of getting angry and wanting to hurt someone who has harmed you," says evolutionary psychologist Michael McCullough, of the University of Miami, who has spent over a decade studying revenge and forgiveness.

It drives crime – up to 20% of homicides and 60% of school shootings are linked to revenge, studies show. And it shapes politics too. Donald Trump's presidential victory, for instance, came as a result of "revenge of working-class whites… who felt abandoned by a rapidly globalising economy," according to an article in the Washington Post. The same sentiment is echoed by many other outlets.

While the topic of aggression is well-studied – its triggers include alcohol, being insulted and narcissistic personality traits – revenge is lesser understood. It is not easy to untangle from violent behaviour, making it a difficult topic to study. David Chester of Virginia Commonwealth University was initially studying aggression but quickly realised that there is often a lot more going on before a violent interaction. He refers to the emotions involved as the "psychological middlemen" –  the thoughts and feelings that come between a provocation and an aggressive outcome. "I was curious, how do you take something like [receiving] an insult and how do you go from that to an aggressive response." The key, he believes, lies in the desire to retaliate. "So by the nature of trying to understand aggression I started studying revenge."

People who are provoked behave aggressively precisely because it can be hedonically rewarding

He set out to uncover more about what causes it. First he, along with his colleague Nathan DeWall of the University of Kentucky, discovered that a person who is insulted or socially rejected feels an emotional pain. The area in the brain associated with pain was most active in participants who went on to react with an aggressive response after feeling rejected. "It’s tapping into an ancient evolved tendency to respond to threats and harm with aggressive retaliation," says Chester.

In a follow-up study he was surprised to find that emotional pain was intricately yoked with pleasure. That is, while rejection initially feels painful, it can quickly be masked by pleasure when presented with the opportunity to get revenge – it even activates the brain's known reward circuit, the nucleus accumbens. People who are provoked behave aggressively precisely because it can be "hedonically rewarding", Chester found. Revenge it seems really can be sweet.

The link between aggression and pleasure itself is not new. The "father of psychology" Sigmund Freud was well aware that it could feel cathartic to behave aggressively, but the idea that revenge provides its own special form of pleasure has only become apparent recently.

To understand this further, Chester and DeWall set up a series of experiments, published in the March 2017 journal of Personality and Social Psychology, where the participants were made to feel rejected by being purposely left out of a computerised ball tossing game. All participants were then allowed to put pins in a virtual voodoo doll. Those in the rejected camp stabbed their doll with significantly more pins. This rejection test was first done remotely online and later replicated with different participants brought into the lab. In the lab version, rather than a voodoo doll, participants acted out their "revenge" by blasting a prolonged, unpleasantly loud noise to their opponents (who were computers, not real people, which the participants were not aware of). Again, those that felt most rejected subjected their rivals to longer noise blasts.

Lastly, to understand the role of emotion in the desire to seek revenge, Chester and DeWall gave participants what they believed was a mood-inhibiting drug (it was in fact only a harmless vitamin tablet). Still, the placebo effect was so strong that the participants who took the "drug" didn't bother to retaliate against the people who rejected them – whereas those that were not given the placebo acted far more aggressively. The placebo group, it seems, did not seek revenge because they believed they would feel no pleasure from doing so.

Taking these results together the team came to a startling conclusion. Not only can revenge give people pleasure, but people seek it precisely because of the anticipation it will do so. "It's about the experience of regulating emotions," says Chester. And it worked. After having the opportunity to get revenge, the rejected individuals scored the same on mood tests as those who had not been rejected.

This finding, however, does need to be taken with a necessary pinch of salt. There are currently no long-term follow up studies on how revenge feels days or weeks after the act. Preliminary – as yet unpublished results – show that revenge-seekers only get a momentary feeling of pleasure, Chester found. "Just like a lot of things, it feels good in the moment. That begins a cycle and it starts to look like an addiction… then afterwards you feel worse than when you started," he explains.

And that might help explain why those who seek the high of revenge fail to anticipate disastrous personal consequences. The footballer Zinedine Zidane, for instance, will forever be remembered for head-butting Marco Matterazzi in the 2006 World Cup. Along a similar vein, Richard Nixon is well-known for his list of foes, the goal being to "screw his political enemies". Some of his dirty tricks later led to his forced resignation.

The question then becomes, why has this seemingly destructive behaviour persisted in our evolution if it can cause us so much trouble?

Far from an evolutionary mistake, revenge serves a very useful purpose  

The answer is that far from an evolutionary mistake, revenge serves a very useful purpose. Michael McCullough puts it this way: although people might say seeking revenge "is really bad for you" – that it might ruin your relationships, for example – the fact that it exists at all is a very good thing. Its main goal is to work as deterrent, which in turn has clear advantages for our survival. Consider prison or gang culture, where if you meddle with the wrong person, revenge attacks are a sure consequence. "If you have a reputation for someone who is going to seek retribution, people are not going to mess with you or take advantage," says Chester. In Leonardo DiCaprio's Oscar-winning performance in The Revenant, so powerful is his desire for revenge that it keeps him alive. With broken bones and open wounds, he drags himself through a hostile and dangerous terrain to avenge his son's killer.

Even the threat of revenge might deter an attack, says McCullough. "The individual who responds to that harm is going to do better than the individual who takes the slap on the cheek and lets the bad guy have his way." Just like hunger, he considers it a primal urge that needs to be itched. Only then can the avenger move on "because that goal has been fulfilled", in a similar way that we only stop feeling hungry after we have satiated our appetite. 

So if a main purpose of revenge is about deterring harm, it is a very good thing indeed. That is not to say, says McCullough, that we should encourage people to indulge in seeking revenge. "We can both appreciate what it's for, understand it's not the product of afflicted minds, and also have an interest in helping people curtail their desire for revenge," he says.

Rejection actually prepares – both mentally and physiologically – the person to defend themselves  

It might also be comforting to know that not everyone acts out on their desire to seek revenge. One 2006 study found that men get more pleasure from the idea of revenge. Male participants were found to have more activity in the reward circuit of the brain than women when they saw cheating opponents receive an electric shock. In another 2008 study, Ozlem Ayduk of the University of California, Berkeley and colleagues, found that those with specific personality types were more likely to act violently after rejection. She found that certain individuals had higher levels of "rejection sensitivity" – who were more likely to expect rejection based on past experiences.

These individuals were also found to be more neurotic and to show anxiety and depression. "They have this tendency to see rejection even where it doesn't exist. Rejection is an existential threat, so that expectation [of rejection] actually prepares – both mentally and physiologically – the person to defend themselves," says Ayduk. Retaliatory aggression for these individuals was therefore a "knee-jerk" reaction to feeling rejected.

We're not doomed to succumb to our revenge impulses

It is important to note that not everyone who has the "rejection sensitive profile" has violent tendencies. Some deal with their feelings of rejection in other ways, such as self-harm. "Somehow this makes people feel that they are in control of something. Aggression is only one of the responses," says Ayduk. 

As well as that, those who are more prone to retaliatory aggression can learn ways to overcome their outbursts, in a similar way that an addict can learn to control his or her urges with various psychological tactics. When Chester and DeWall peered into individuals' brains during one of their revenge studies, they found that those who were able to restrain themselves from acting out showed brain activation in the lateral pre-frontal cortex, an area known to be important for reasoning and inhibiting impulsive actions. "So we're not doomed to succumb to our revengeful impulses. We have evolved this very sophisticated pre-frontal cortex that can inhibit impulsive behaviour and guide it to more social outcomes. There is hope whether we're aware of it or not."

So next time you are plotting revenge against someone who has wronged you, know that the anticipation of revenge may feel good in the moment, but don't expect these hidden "upsides" to last for long. Rather, understand that this feeling is there for a very good reason, and it could well have protected many of your ancient ancestors from being taken advantage of.

-

Melissa Hogenboom is BBC Earth's feature writer. She is @melissasuzanneh on Twitter.

Join 800,000+ Future fans by liking us on Facebook, or follow us on Twitter.

If you liked this story, sign up for the weekly bbc.com features newsletter, called “If You Only Read 6 Things This Week”. A handpicked selection of stories from BBC Future, Earth, Culture, Capital, and Travel, delivered to your inbox every Friday.