True love knows no obstacles, even if the obstacle in question is a pack of angry mongooses.

New research reveals that female mongooses take enormous risks to be with their perfect partner. They choose to mate with males from rival groups, even though that could get them embroiled in lethal fights.

Banded mongooses, much like their more famous cousins the meerkats, live together in large packs in the grasslands of Africa. They are small mammals, feeding on insects, spiders and occasionally snakes. They work together in groups to raise pups and care for elderly pack members.

We follow each animal from its birth to its death

Scientists have been studying banded mongooses in Queen Elizabeth National Park in Uganda every day for 20 years, and we now have a vivid picture of how their societies function.

"It's a bit like watching a long-running soap opera," says lead researcher Hazel Nichols of Liverpool John Moores University in the UK. "We follow each animal from its birth to its death, recording its growth and development, along with finding a mate."

In a setup reminiscent of a Shakespearean tale, females in the pack are expected to marry one of their own, and dominant males closely guard their chosen mate. But like in any good story, the characters don't always do as they're told.

New research by Nichols and her team shows that females often break the rules and look for mates outside the group.

When two packs meet, savage fights often break out

Their latest genetic analysis, published in the journal Behavioural Ecology, showed that males from other packs were fathering nearly 20% of pups in the group.

But females only get the opportunity to mate with outside males during pack warfare – a dangerous time for romance.

Mongoose packs don't tend to play well with others, and when two packs meet, savage fights often break out. Getting involved is a bad idea: 12% of all mongoose deaths occur during these vicious encounters.

Why are females risking so much to be with their star-crossed lovers?

Nichols and her team claim it's all about finding the best genes for their offspring. When females mated with males from other packs, they produced pups that were heavier, healthier and more likely to survive to independence.

Female mongooses try to avoid mating with their brothers and uncles

For banded mongooses, moving to a new pack can be very dangerous, so they often choose to stay at home and reproduce in the family group where they were born. This means that for many females, potential mates within their pack are close relatives.

But just like humans and most other animals, female mongooses try to avoid mating with their brothers and uncles.

The team found that females were more likely to pursue males outside the group when their pack consisted mainly of family members, providing no suitable mates.

Mating with close relatives is known as inbreeding. It can be dangerous because it reduces genetic diversity, making harmful mutations more common.

There seems to be evidence in both meerkats and banded mongooses that avoiding inbreeding brings benefits

Over several generations these mutations can lead to "inbreeding depression", which makes animals smaller, weaker and less likely to survive.

Inbreeding depression has been identified in many species. It is a particular problem for animals that live in harsh environments where leaving your family group can be fatal.

Breeding with males from other packs allows females to bring some fresh blood into their group, reducing the risk of inbreeding depression.

"There seems to be evidence in both meerkats and banded mongooses that avoiding inbreeding brings benefits," says Marta Manser of the University of Zurich in Switzerland. But we don't fully understand what's happening. "We only partly understand the underlying mechanisms, and we don't know if these benefits continue later in life."

Meerkats live in societies similar to those of banded mongooses. Previous research has shown that inbred meerkat pups grow more slowly and are less likely to survive.

Female mongooses are able to make carefully-calculated decisions to secure the best future for their offspring

Around 20% of meerkat pups are fathered by males from another colony. This suggests that, like banded mongooses, female meerkats are forced to look outside the group for their ideal mate.

Nichols' new study is the first to show female mongooses actively choosing to mate with outsiders when the options available in their own pack are poor.

"They modify their behaviour to balance the risk of inbreeding with that of getting injured during fights between packs," says Nichols.

The results suggest that female mongooses are able to make carefully-calculated decisions to secure the best future for their offspring.