The succulent sweet fig is a nesting ground for thousands of tiny fig wasps.

The fig tree and fig wasp share a long and unique mutualistic association, one that benefits both equally. Figs depend on wasps to make their seeds and distribute their pollen. In turn, the fig tree acts as a womb where the fig wasps can reproduce.

This association has existed since the time of the dinosaurs 65 million years ago. Over the millennia both members have adapted to the other: for instance, wasps and seeds take a similar amount of time to develop.

But this friendly alliance sometimes turns sour. In some cases, a fig tree will trick its fig wasp partner. The tree benefits, while the wasp dies.

There are over 750 species of fig trees, all belonging to the genus Ficus. Their pollinating wasps belong to the family Agaonidae, which contains 20 genera.

The mother wasp now has only 24 hours to live

About half of figs are "monoecious", meaning each tree produces both male and female flowers. The others are "dioecious" and have two kinds of figs on separate plants: "gall figs" with male and female flowers, and "seed figs" with female flowers only.

Fig trees produce their flowers within enclosed green spherical structures called syconia. Each syconium contains hundreds or even thousands of flowers.

In monoecious species, the female flowers mature first, signalling the syconium to release a fragrant scent. Enticed by the odour, a pregnant female wasp enters the syconium through a tiny opening in the centre.

The wasp is carrying pollen from the flower where she was born. Once inside the syconium, she deposits the pollen, fertilising the flowers.

Their purpose completed, the wingless male wasps die

Then she lays her eggs in the female flowers, using long tubes called ovipositors. The mother wasp now has only 24 hours to live. Before she dies, like any good mother, she ensures the survival of her babies.

She injects the flowers with a chemical that transforms them into fat, rounded structures called galls. When the eggs hatch, these galls will provide food and shelter for the young offspring. They are fig wasp nurseries.

The young wasps will grow to adulthood, and even mate with each other, within the syconium. Then the males and females face very different fates.

The male wasps are blind and wingless. They bite through the syconium, creating an opening for the winged females to fly out. Their purpose completed, the wingless male wasps die, and the syconium ripens into mature, fruit-containing seeds.

Meanwhile the female wasps collect pollen from the male flowers, which have just matured. They stuff the pollen into specialised pollen pockets, located above the abdomen.

The nature of dioecious fig trees creates an evolutionary conflict, one that the fig wasps seem to be losing

They then leave in search of another fig syconium. There they will deposit their cargo of pollen, lay eggs, and start another life cycle.

Thanks to their short life cycle of just two months, the fig wasps ensure that the fig trees produce fruit all year round. As a result, in rainforests many birds and animals depend on figs for food, making them keystone species that support the entire ecosystem.

By nesting in the figs, the fig wasps indirectly help in maintaining biodiversity and population density. It is a stable partnership that benefits both members, and the wider ecosystem.

But in the case of dioecious fig trees, all bets are off. These trees are far less cooperative.

Dioecious fig trees are subtly different to monoecious ones. In particular, their flowers tend to have shorter stalks than those of monoecious species.

The wasps can still nest in dioecious trees, but their young can only develop in male flowers

The fig wasps have changed along with them. Morphological data shows that wasps pollinating monoecious figs tend to have long ovipositors, while those that pollinate dioecious figs have short ovipositors.

Dioecy evolved much more recently, as did the altered wasps. Fossil fig wasps have been found in England that date from 34 million years ago. They have short ovipositors that are almost indistinguishable from those of modern species associated with dioecious figs.

The nature of dioecious fig trees creates an evolutionary conflict, one that the fig wasps seem to be losing.

The wasps can still nest in dioecious trees, but their young can only develop in male flowers. Female flowers have comparatively long stalks, so the female wasps' short ovipositors cannot reach inside to lay eggs and turn the flowers into galls.

A female wasp cannot lay its eggs in a female flower, so when it enters it commits reproductive suicide

Despite this, some female wasps enter the female flowers anyway. From the wasps' point of view this is utterly futile, as it means they cannot reproduce.

At first scientists thought that they might be doing it because the male flowers were not yet receptive, leaving them no other option. But in a study published in February 2016, Renee Borges at the Indian Institute of Science, Bangalore and her colleagues found that the wasps sometimes enter the female flowers even when the male flowers are receptive.

It turns out that the female flowers attract the wasps by mimicking the scent of male flowers. The fig trees are deceiving the wasps, a Machiavellian strategy that furthers the reproductive goals of the fig tree but spells doom for the wasps.

A female wasp cannot lay its eggs in a female flower, so when it enters it commits reproductive suicide. However, the female flower still gets pollinated and goes on to produce seeds.

This raises an obvious question. If this strategy is harmful for the fig wasps, and the figs have been using it for tens of millions of years, why haven't the wasps bailed on the figs, or started fighting back?

Borges says it may all be down to genetics.

The figs and the wasps are utterly dependent on each other, but that does not mean they are "loyal"

Fig wasps are inbred, because they often mate with their own brothers or sisters inside a syconium. So even if some lineages die out, the wasps that successfully breed in male figs probably share lots of genes with those that have committed reproductive suicide in female figs.

This leads to a surprising conclusion. Even those wasps that mistakenly enter the female figs will see their genes passed on to the next generation, because their sisters and cousins will breed successfully. This means there is not much evolutionary pressure on the wasps to fight back, or to abandon their dioecious hosts.

Meanwhile, the deceptive dioecious plants have not outcompeted the honest monoecious ones. "The fact that both monoecy and dioecy exist could mean that, at any point in time, one strategy is not more advantageous than the other," says Borges. "If not, by virtue of natural selection, one would cease to exist."

There is a lesson here about the nature of cooperation. The figs and the wasps are utterly dependent on each other, but that does not mean they are "loyal". In a sense each is always exploiting the other. It is just that, most of the time, and largely for circumstantial reasons, ­the exploitation is fairly benign.

Follow BBC Earth on Facebook, Twitter, and Instagram. If you liked this story, sign up for the weekly bbc.com features newsletter.