When Thomas the orphaned chimpanzee died, his companion Pan appeared to grieve for him. And Pan was not the only one.

The other chimps in the group chose to stay around Thomas, even though it was their usual feeding time. Many of them touched Thomas's body. One dominant female even brushed his teeth with grass before his corpse was taken away.

Perhaps more surprisingly, two species of monkey – much more distantly related to us than apes – have been observed behaving similarly in the wild. The monkeys seemed to acknowledge, and even mourn, their dead.

Because it involves staying out in the open, this "grieving" behaviour could make the monkeys vulnerable to predators. So the question is, why do they do it? Figuring that out could help us understand how grief evolved.

Warning: There are images below that some readers may find distressing

The pair then climbed into a nearby tree. DM must have been very weak at this point, because about 30 minutes later she fell and hit her head on a rock. "She lay motionless except for sporadic twitching and faint groans," the authors report.

After walking only a few metres she fell over and died

DM was clearly seriously injured. The other adults in her group immediately came down from the tree and gathered around her to groom and caress her for over an hour. They also emitted alarm calls.

As it began to get dark, most of the group left, but the dominant male stayed by her side.

DM finally stirred and tried to follow the other monkeys. But after walking only a few metres she fell over and died.

The dominant male gently tugged her hand a few times, groomed and embraced her. He also groomed himself while he was looking at her. He stayed out much longer than he normally would, but eventually retreated to the safety of the mountain.

The monkeys showed an understanding of the change in the behaviour

When Yang returned from the field he sent his insights to primatologist James Anderson at Kyoto University in Japan, a specialist in "primate thanatology": the study of death.

Anderson says it is hard to say whether the other monkeys knew DM was dying, but "they were clearly more attentive and more affiliative towards her than they normally would be."

The monkeys showed an "understanding of the change in the behaviour that suggested compassion towards a very seriously ill and ailing individual," he says.

Researchers had been observing a group who spent a lot of time near tourist sites in Ifrane National Park in Morocco. The monkeys often fought over food near busy roads, and as a result some of them were killed by passing vehicles.

In the first and most informative observation, the group's highest-ranking female, Mary, was hit by a bus. Although seriously injured, she was able to retreat to a nearby tree.

Two adult males inspected and touched her wounds. After the other monkeys left for their usual sleeping areas, one male returned and groomed her. After dark, another monkey – identified as IS – sat nearby and stayed there all night.

One displayed anxiety-related behaviours

Early the next morning, the researchers returned to find that Mary had died. IS was still there and stayed near her body until mid-afternoon, only then leaving to feed for a short while. This was surprising, as macaques usually spend a lot of their day eating.

Other members of the group also spent time in the tree with the female's corpse. Some groomed her. One displayed anxiety-related behaviours, including scratching and yawning.

The body was removed in the evening at which point the dominant male screamed and charged at the researchers.

One of the researchers who witnessed these macaque deaths was Patrick Tkaczynski of the University of Roehampton in the UK. He says it is not surprising that the macaques responded as they did.

It's not easy to completely and suddenly rupture an emotional bond with another individual

"Barbary macaques have a reputation for being 'hippies' compared to a lot of other macaque species, and are known to form long-term social bonds," says Tkaczynski. "Having these strong social bonds might predict particularly strong responses to the loss of their 'friends' or relatives."

Being so social, it makes sense that they would show signs of stress and anxiety when their companions die.

"It's not easy to completely and suddenly rupture an emotional bond with another individual," says Anderson. "I think that can explain the desire or the reluctance to leave dead individuals." (see image below)

Although it is clear that a companion's death has caused the monkeys distress, Tkaczynski and Anderson are both hesitant to say that the monkeys are actually grieving. Others are more convinced.

Anthropologist Barbara King of the College of William & Mary in Williamsburg, Virginia has studied animal grief extensively. She says both of the new reports offer compelling evidence of grief.

You see an animal taking a responsibility for gate-keeping the body

"My definition requires that we know there's been a change in the survivor's behaviour after some friend, companion or relative dies," says King. "I'm looking for evidence of emotional distress, change in behavioural patterns that last for a while, some evidence of response from an animal that has a particularly strong relationship with the dead. All that is there."

The chimpanzee case and the two monkey cases all show the same basic pattern, she says.

"You see an animal taking a responsibility for gate-keeping the body, some type of unusual emotional response by the animal closest to the dead ones, and a sustained response that goes beyond the first five minutes or hour."

Mothers continued to carry the corpses of their babies after they had died

They found that glucocorticoid levels were significantly higher in the four-week period after losing a group member. This same hormone is associate with bereavement in humans. Baboons that did not experience a loss did not have elevated levels of the hormone.

We also know that female monkeys have strong ties to their offspring, which can persist after death.

Incidents like these suggest that these monkeys are aware that their companions have died, and that death can have a powerful impact on their lives.

Having friends can literally help us live longer

"Why wouldn't we expect them to grieve?" says King. "We know that monkeys are smart creatures with very well-worked-out hierarchies, social attachments that are very strong... It doesn't surprise me at all that it's absolutely natural for these animals to feel their loss and express it in ways we can understand."

Their behaviour could give us some insight into why we grieve.

Humans, like all primates, live in highly social worlds with strong ties with our friends and family. We rely on social relationships for our health and welfare. Studies indicate that loneliness can damage our health and even cause elderly people to die earlier.

In other words, having friends can literally help us live longer. Friendships can also lower our blood pressure and help us cope with stress, other research suggests.

Given that, it makes sense that losing someone can have a dramatic impact on our behaviour, and can cause us physiological distress. Our grief can be seen as a direct consequence of our having adapted to be highly social, says Tkaczynski.

There can also be a positive side to grief.

Their behaviours reflect our shared evolutionary history of social bonding

When a friend or family member dies, it brings people together and supports "mutual bonding", says Carolyn Ristau of Barnard College, Columbia University in New York, US. This suggests that grief might serve to promote and strengthen relationships.

"Good relationships serve many positive functions both for the individual and for the group as a whole," says Ristau. "In various species, a closely-bonded conspecific may help with care of the young, may join together in a food seeking group, protect against predators."

If you see grief as a consequence of being social, it is not surprising that monkeys react to death much like we do. Their behaviours reflect "our shared evolutionary history of social bonding," says Tkaczynski.

Melissa Hogenboom is BBC Earth's feature writer. She is @melissasuzanneh 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, Travel and Autos, delivered to your inbox every Friday.