In a dark cave in Tabasco, southern Mexico, near the village of Tapijulapa, lives a community of molly fish. There would be nothing remarkable about this, except that the cave is poisoned with hydrogen sulphide, a toxic gas deadly to life.

The fish have developed a suite of remarkable adaptations to their dark, toxic world. They may even have come up with a way to survive a local religious ritual that involves poisoning them.

In fact, the cave mollies seem to be well on their way to becoming a distinct species. That might seem odd, given that there is no barrier separating them from the light-drenched pools outside the cave where regular mollies live.

But in this case, the reasons might be sticking to the cave for a rather direct reason. Lurking at the cave mouth is a ferocious, gruesome predator.

The cave of the mollies is called Cueva del Azufre, literally "Sulphur Cave" – or, confusingly, Cueva de Villa Luz ("Cave of the Lighted House") and Cueva de las Sardinas ("Cave of Sardines").

It is fed by many natural springs and streams, which form several pools inside the cave. In each pool swim hundreds if not thousands of fish.

The fish are exposed to concentrations of hydrogen sulphide 50 times higher than those generally considered toxic

A creek flows out of the cave forming the milky "El Azufre", which meanders for approximately 0.9 miles (1.5km) until it falls over a spectacular waterfall into the Rio Oxolotan.

Natural oil deposits and volcanic activity in the area mean that the water is enriched with hydrogen sulphide. The poisonous gas has also leaked into the air of the cave.

In fact, the air is so toxic in parts of the cave that researchers have to wear protective gear and respirators.

If they were to remove them they would immediately experience a burning sensation in their eyes, and throat irritation. After just two minutes they would lose their sense of smell, their breathing would be depressed, they would become drowsy and eventually pass out. After 48 hours they would likely be dead.

It is not just the air of the cave that is poisoned. In the water, fish are exposed to concentrations of hydrogen sulphide 50 times higher than those generally considered toxic for aquatic species. Oxygen, meanwhile, is much less available than in other aquatic environments.

Most forms of life would be dead within minutes, yet the molly fish remain unharmed. Just how do they do it?

On the surface there is nothing special about the Atlantic molly fish (Poecilia mexicana). The small, iridescent pearly-coloured fish is widespread across Central America, where it usually lives in freshwater streams.

But when biologists stumbled across a community of mollies living in the cave they were baffled. They are the only known mollies to live in a cave, and the only known example of a fish being able to survive in such a poisonous environment.

About 170 of the fish's 35,000 or so genes were involved in detoxifying and removing the poison

Michi Tobler from Kansas State University in the US has spent decades researching the fish. Tobler believes that, in order to survive, the mollies have had to change both their behaviour and their genes.

"Fish avoid taking in too much hydrogen sulphide by breathing directly at the water's surface," says Tobler. "This compensatory behaviour, which is called aquatic surface respiration, increases their ability to acquire oxygen in the hypoxic [oxygen-depleted] environment, and it likely also minimises hydrogen sulphide uptake by the body."

Tobler's research has shown that aquatic surface respiration is critical for short-term survival. If fish are denied access to the water surface, they quickly die.

As well as limiting the amount of toxin that enters their body, the fish are also able to detoxify the hydrogen sulphide once it has entered their system.

Hydrogen sulphide is deadly because it turns off energy production in cells, by interfering with specific proteins. To stop their cells from shutting down, the fish switch to anaerobic metabolism, which is an alternative but much less efficient of producing energy that does not involve oxygen.

Few other animals have followed the mollies into the cave

When Tobler and his team analysed the cave molly's DNA they found that, compared to their freshwater cousins, the fish have increased their expression of genes that code for proteins that break down hydrogen sulphide into nontoxic forms and excrete it. In fact about 170 of the fish's 35,000 or so genes were involved in detoxifying and removing the poison in this way.

This means that although the toxin can still invade the fishes' bodies, they have evolved a way of neutralising it.

It is not just toxic gases that the molly has to contend with. The total darkness in the cave has forced the fish to adapt in other ways.

Their environment is so extreme that few other animals have followed the mollies into the cave. This means there is less food for the fish to eat and resources are limited. The fish have coped by reducing their energy expenditure.

They have smaller brains, possibly to conserve energy

Their bodies have lost their colourful pigmentation, an unnecessary waste of energy and resources in a dark environment where visibility is poor.

They have also developed smaller and less sensitive eyes than their cousins living outside. Instead of eyes the fish rely on a hypersensitive pressure detector that runs down each side of their bodies, known as the 'lateral line' to sense disturbances in the water.

They also have a higher density of taste buds to sense their environment.

In order to extract the maximum amount of oxygen from the water, the mollies have grown larger heads and gills. They also have smaller brains, possibly to conserve energy.

As well as changing their bodies, living in the cave has changed how the mollies behave.

Cave mollies have a different diet to their surface ancestors. They feed on bacterial films and insects instead of algae. In response, their jaws and intestines have changed.

Cave mollies are also less aggressive than their freshwater cousins. This could be because aggression is quite a costly behaviour, and is not advisable therefore when resources are limited. Cave mollies also do not hang out together in shoals, and are more solitary in general.

Living in darkness has also changed how the mollies choose their mates. Female mollies prefer larger males, but whilst surface fish can quickly see which males they fancy, in darkness this is more difficult.

Instead the fish rely instead on their lateral line to sense disturbances in the water. The greater the disturbance, the bigger the male.

"Unlike their surface ancestors, cave mollies have evolved the capability to communicate in complete darkness," says Tobler. "Cave mollies can assess the body size and nutritional condition of a potential mating partner without seeing them."

Another difference between the cave molly and its ancestors is the fact that molly females – which give birth to live young rather than laying eggs – now produce fewer but larger offspring. This makes sense, as larger fish are more protected against the effects of the poison.

As if things were not bad enough for the poor molly – toxic poison in the water, total darkness, slim food pickings – it also has to contend with the local population of humans poisoning it every year as part of a religious ritual.

In a ceremony designed to ask their gods for rain, every year in spring the Zoque people of southern Mexico head to the local cave and toss leaves containing a paste made from ground barbasco root into the water.

Suddenly fish begin to float up to the surface, seemingly as a gift from the underworld. The Zoque then take them home for supper.

It has become genetically distinct from other mollies, even those living just metres away from the cave mouth

Barbasco root contains the fish poison rotenone, which is a powerful anaesthetic.  However, not all of the fish are affected. Some seem to have developed resistance to the drug.

Tobler wondered how the ritual might affect the fish. He collected molly fish from the sulphurous cave used in the ritual, and then others from water upstream. He then mimicked the religious ceremony, adding mashed-up barbasco root to the two separate tanks.

He found that male fish were much more susceptible than females, and that the cave fish had a much higher tolerance to the barbasco poison than the fish upstream.

In a case of evolution in action, those fish that have developed a resistance to the toxin survive to pass on their genes to the next generation. Therefore, over time the proportion of fish immune to the barbasco poison has risen.

In fact the cave molly has become so specialised at living in its environment that it has become genetically distinct from other mollies, even those living just metres away from the cave mouth.

In an experiment Tobler collected fish from a chamber at the front of the cave that receives some light, in two chambers deep inside the cave that are pitch-black, and in a creek that spills out of the cave. He then compared these to fish found on the other side of the river Rio Oxolotan.

There are no physical barriers separating the fish from each other

He found that the fish inside and around the cave were completely genetically isolated from those found across the river.

What's more, fish in different chambers were also genetically quite different to each other, and were very different to those found just outside the cave. Tobler believes this is due to the fish adapting to their own unique environment, as each pool differs in darkness levels, and some pools contained more hydrogen sulphide gas than others.

The cave mollies are so genetically different to surface mollies that Tobler believes they are well on their way to becoming a separate species. But why this is happening is still something of a mystery.

The cave pools are all connected to each other and flow openly out into the creek outside the cave. There are no physical barriers separating the fish from each other, nothing to stop the fish and their genes from mingling. What is preventing the cave fish from leaving their toxic environment, and joining the surface fish?

It seems that the Belostoma bug is keeping the fish apart

The answer may lie in a gruesome predator that lies in wait between pools.

Giant water bugs (Belostoma) lurk near the water surface, ready to stab any unsuspecting molly with their spear-like mouthparts. These predators hunt throughout the sulphur cave and outside, preying on cave and surface molly alike.

However, Tobler discovered that both communities of fish are better at evading capture when they are in their own environment.

Tobler put cave mollies and surface mollies together in large plastic bottles, which mimicked the cramped confined environs of the cave passageways. He then added the bug predators to the bottles.

Next, he placed some bottles inside the dark cave, and others outside in the mouth of the cave. After one day he returned to see which mollies had been killed by the bugs.

It can survive being poisoned, living in toxic waters and being preyed on by giant bugs

In the bottles placed in the light, it was the cave mollies used to living in the dark that made up 80% of victims. However, inside the cave the situation was reversed, and it was the light-living surface mollies who made up two-thirds of the victims.

Even if captured mollies were allowed to acclimatise to the environments for a day before the predator was added to the mix, they still suffered the same proportion of attacks in the two environments.

It seems that the Belostoma bug is keeping the fish apart, as any fish that crosses from the light to the dark – or the dark to the light – instantly becomes more vulnerable to predator attack.

"Surface fish are better than cave fish at escaping predators in the light, and cave fish are better than surface fish when it's dark," says Tobler. "Such performance trade-offs are sufficient to keep the cave and surface populations separate."

It seems that the cave molly has a strong case for being the toughest fish in existence. It can survive being poisoned, living in toxic waters and being preyed on by giant bugs. But why the molly is the only fish to have evolved this toughness is less certain.

Giant water bugs lurk near the water surface, ready to stab any unsuspecting molly

"The hydrogen sulphide concentrations inside the cave are orders of magnitude higher than what most animals can tolerate," says Tobler. "Why mollies and not other species have managed to adapt is difficult to say from a scientific perspective."

The answer might lie in part in the fact that mollies are live-bearing fish. For some reason this trait seems to make fish more tolerant to environmental stressors such as high temperature, salinity, and low oxygen, says Tobler.

Whatever the reason, it is difficult to avoid admiring a small fish that has learned to live with some very big problems.