The name "Tasmanian devil" may bring up images of cartoon tornados and scattered debris. The Warner Brothers character Taz was portrayed as dim-witted, destructive and wacky. But real Tasmanian devils are anything but.

"They all have very unique personalities," says Abram Tompkins, supervisor at captive breeding facility Devil Ark in New South Wales, Australia. "They're not the feisty, ferocious animals that most people perceive them as. Most devils are actually quite timid, yet curious."

The Tasmanian devil (Sarcophilus harrisii) is an endangered marsupial found only on the Tasmanian Islands off the south-east coast of Australia. It may grow to only 8kg, but that still makes the Tasmanian devil the largest living carnivorous marsupial on Earth.

Marsupials are a small but endearing branch of the mammalian family tree. Along with the egg-laying "monotremes", like the Platypus, they are sisters to the placental mammals, a group that includes everything else, from humans to elephants and from mice to lions.

They're not the feisty, ferocious animals that most people perceive them as

Unfortunately, marsupials have not fared well with the expansion of human civilisation, and they are now restricted to small pockets of habitat in Australasia and South America. The Tasmanian tiger, or Thylacine, was another carnivorous marsupial once found in Australasia. It was driven to extinction in the early 20th Century. Weighing up to 30kg, the Tasmanian tiger held the title of "largest living carnivorous marsupial" until it was wiped out.

Like other marsupials, the Tasmanian devil has suffered major population declines due to loss of habitat, hunting, invasive species and disease. Once common across Australia and Tasmania, the devils were lost from the Australian mainland around 400 years ago. They are now only found in the wild on Maria Island, Robbins Island and the island of Tasmania.

In Australia, the devils faced competition from introduced dingoes, and hunting by Aboriginal Australians. In Tasmania, however, they have been pushed to the very brink of extinction by an entirely different kind of threat.

Evading the Immune System

The last remaining populations of devils are now being ravaged by a fatal form of cancer known as Devil Facial Tumour Disease, or DFTD. This unusual disease can be transmitted between devils, in one of just a handful of examples of contagious cancer.

The last remaining populations of devils are now being ravaged by a fatal form of cancer

First discovered in 1996, DFTD causes tumours to form on the face and neck of the animal, killing infected devils within just three to five months. Worse, the disease is common among young adults in their reproductive prime, limiting the population's ability to rebound after an infection.

Cancers are very good at hiding from the immune system of their host. That is how they are able to grow and spread unhindered, and why they are so dangerous.

But most cancers are not contagious, because while the cancer cells can hide from their own immune system, they are immediately flagged up as "foreign" cells by another individual's immune system.

Your own unique set of molecular markers, known as the major histocompatibility complex (MHC) are present on every cell in your body, labelling each one as "self". This is what makes transplant medicine so complicated: the labels on anybody else's cells will be quickly identified as "non-self" by their unique MHC molecules, and rejected by the body.

Cancer cells still carry these unique molecular identifiers that label them as belonging to a particular person, so one individual cannot usually transmit cancer to another.

The cancer cells are difficult for the recipient’s immune system to recognise as non-self

Unfortunately, this simple mechanism for recognising foreign cells has failed in the case of DFTD. DFTD cancer cells are transmitted from one devil to another during their vicious fights, in which they often bite each other's faces. The cells do not express MHC molecules on their surface, making it difficult for the recipient's immune system to recognise them as non-self.

"The major histocompatibility complex class I molecule (MHC-I) occurs on all nucleated cells and allows the immune system to distinguish 'self' from 'non-self'," says Ruth Pye, a practising vet and PhD student studying the disease at the University of Tasmania in Hobart. But DFTD cells evade the immune system by inhibiting the production of MHC-I molecules on their surface, she explained.

"This doesn't provide the whole story though," says Pye. She explains that one type of cell found in the immune systems of many species of mammal is the Natural Killer (NK) cell. Their job is to find cells that have no MHC-I molecules, identify them as abnormal, and kill them. Just as a person with no fingerprints immediately arouses suspicion, cells without any MHC-I molecules should not be allowed to slip under the radar.

Somehow, DFTD is able to evade natural killer cells, too. Perhaps Tasmanian devils simply lack natural killer cells. However, this explanation seems unlikely as natural killer cell receptor genes have been identified in the genome of Tasmanian devils, and receptor molecules are present in the devils' milk. Pye suggests that the cancer may be able to produce molecules that deflect natural killer cells, or that suppress the immune system, but nobody knows for certain yet.

It is not all down to the disease's sneaky tactics, though. The incredible ability of DFTD to spread from one devil to another is also partly down to the devils' genetics. Tasmanian devils have very low genetic diversity: most remaining Tasmanian devils are almost identical at the genetic level.

Safety in diversity

Genetic diversity is crucial for the MHC system to work. Genes determine your unique MHC profile, but if everyone's genes are exactly the same, everyone's MHC profiles will be the same. For most creatures, MHC profiles are uniquely individual because the MHC profile itself is controlled by many genes. The chances that two individuals will be identical for every single gene are very small. But if genetic diversity is low, as is the case for the devils, it becomes more and more likely that two animals will be indistinguishable to the immune system.

The ability of DFTD to spread is also partly down to the devils' genetics

Katherine Belov, professor of comparative genomics at the University of Sydney, explains: "Because devils have very low genetic diversity they are essentially immunological clones," meaning that "the cells of others are similar to their own."

It was first assumed that Tasmanian devils had lost their life-saving genetic diversity quite recently, as their population declined and became trapped in small pockets of habitat. Small populations tend to harbour relatively little genetic diversity and inbreeding can exacerbate the problem.

But a study of ancient DNA from museum specimens dating back as far as 3,000 years showed that low diversity had been a feature of the devil's genome for centuries – long before European settlers arrived. This might explain why the creatures have suffered frequent disease outbreaks and population declines.

Their isolation only makes the situation worse. As Tasmanian devils are now restricted to small pockets of habitat on islands, they are unable to move away from disease outbreaks when they strike.

Their most recent disease epidemic, DTFD, has had an alarming effect on the remaining populations of Tasmanian devils. The disease has now spread across almost the entire species' range, causing devastating declines of between 80% and 90% over just two decades. Some had begun to fear Tasmanian devils were doomed to extinction.

The disease has caused devastating declines of between 80% and 90% over just two decades

But despite studies predicting their demise, populations that have been living with DFTD for years are still surviving. The clues to why are only just starting to be unravelled.

A study published in October 2016 found one explanation for the devils' resilience: their immune system is showing signs of fighting back. Pye and an international team of researchers detected antibodies against DFTD in their blood – a hallmark of an immune response against the disease. One devil tested even had tumour-killing immune cells in their tumour. This tells us that "devils can produce an immune response against DFTD, and death isn't the inevitable outcome of infection," says Pye.

Although the discovery is exciting, Pye warned that they have found no evidence that this immune response is reducing the effect of DFTD in the population of wild devils yet. Pye hopes that the effects of increased immunity and genetic evolution "will become evident over time".

What triggered these immune responses is not yet clear. Although the disease has been raging for 20 years, that is actually very little time for evolution to change the devils' genes and adapt to DFTD. "Evolution is usually regarded as a slow process," says Pye.

DFTD reminds us that evolution can be sometimes rapid, if natural selection is strong enough. DFTD has wiped out over 80% of the devil population, producing extremely strong evolutionary pressure to adapt. A study published in August 2016 revealed two regions of the Tasmanian devil genome that have changed significantly over the last 20 years. Both regions are involved in immunity and cancer prevention.

Tasmanian devils have started breeding younger in life

In all three populations of devil, the same signatures of rapid evolution are present in the same genes and the same genomic regions. Whether these changes are linked to the immune responses detected by Pye remains unclear.

In response to the devastation of DFTD, Tasmanian devils have also started breeding younger in life, which Pye thinks may have been crucial to allowing devils to survive DFTD, albeit in relatively small numbers. By breeding at just 12 months, female devils are able to attempt at least one litter before succumbing to DFTD. Reproducing younger also means the devils have shortened their generation time, perhaps inadvertently helping speed their evolution to fight the disease.

These recent discoveries have given new hope to long-term conservation projects trying to save the devils from extinction.

Captive breeding has been a major part of the conservation effort, by maintaining an "insurance" population that can restock wild populations that have been ravaged by DFTD.

"Over 50% of devils on the Australian mainland are housed at Devil Ark," says Tompkins. Devil Ark is part of Save the Tasmanian Devil's Captive Population Programme. "We house healthy individuals free from the tumour and we focus on breeding genetically diverse devils," he adds. Together, the programme's more than 30 members house over 500 breeding, uninfected individuals, representing as much as 98% of the remaining genetic diversity in living Tasmanian devils.

Captive-bred devils have been immunised with a trial vaccine

Another key prong in the conservation fork is developing a vaccine to help boost the devil immune system into fighting DFTD. Studying the genome, and the genes specifically active in DFT cells, has shown that all DFTD cells are genetically identical. DFTD cancer cells from a single original source have spread through almost the entire population of Tasmanian devils. This cloud might have a silver lining, though, as it should be easier to develop a precise, effective vaccine against a genetically-uniform opponent like DFTD.

Just such a vaccine has now been developed, and is undergoing field trials across Tasmania. The vaccine makes use of naturally-occurring signalling molecules to stimulate an immune response against the DFTD cancer cells.

In September 2015, 20 captive-bred devils were immunised with the trial vaccine, and released into the wild in Narawntapu National Park in northern Tasmania. Another 39 animals were released in Forestier Peninsula in the southeast later that year. Although several of the released animals were killed on roads, at least two succeeded in producing offspring in 2016, and scientists continue to watch their progress carefully using motion-triggered cameras and traps. Life for captive-bred animals as they learn to live in the wild can be tough, and not all of these devils will make it. But if their immunisation does the trick, they will hopefully survive long enough to produce the next generation of devils.

Devils may harbour their own medicine

In 2016, a further 33 devils were released into Stony Head military training area in northeast Tasmania, where they will mix with diseased devils for the first time. This is an important stage; testing how the vaccine fares in wild populations. This trial included wild vaccinated individuals as well as captive-bred devils, and most individuals released were fitted with a GPS collar to enable scientists to precisely track their survival in the wild.

The vaccination programme looks promising, and combined with rapid evolution and increasing immunity, offers some hope for the survival of the Tasmanian devil.

Another potential aid in the fight against DFTD might come from the devils themselves. A study published in October 2016 found that milk from Tasmanian devils, the crucial food they provide to their young as they develop inside the pouch, contains several powerful antibiotic molecules called cathelicidins.

"When marsupials are born they do not have an immune system. The immune system develops while they are in the pouch," explains Belov, who led the study. "During this time they are protected by powerful antibiotics which are produced in the mother's milk, secreted in the pouch and even secreted by the skin of the young themselves."

Humans produce one natural cathelicidin, but Tasmanian devils produce an extra five types, and another marsupial – the gray short-tailed opossum (Monodelphis domestica) – has twelve types of cathelicidins. Marsupial milk may be an important source of new antibiotics able to treat resistant strains of bacteria like MRSA and Vancomycin-resistant Enterococcus. "These [cathelicidins] are awesome – and can even kill multi-drug-resistant bacteria," Belov says.

Milk from Tasmanian devils contains several powerful antibiotic molecules

Belov believes these cathelicidins may also be able to help treat DFTD one day. "Initial tests look positive," she says, "but we have only done tests in the lab." The next step will be to trial these potentially life-saving proteins on real animals.

With so many positive twists in the tale of the Tasmanian devil, you might assume the devil is out of the woods. "Unfortunately, no!" says Pye.

Demonstration of immune responses against DFTD is encouraging, and so is the suggestion that genetic selection is occurring in response to DFTD. But she reiterated that the benefits of these developments have not been felt yet.

"It will be really interesting to find out if this genetic selection is associated with increased survival or any resistance to DFTD," she says. But so far there is no evidence of that.

Belov agrees. "We have also seen the tumour evolve. We don't know which way it is evolving yet – more aggressive or less aggressive," she warns.

Just as one foe may be in retreat, another emerges. In January 2016, Pye published a study revealing that a second contagious cancer has been detected in Tasmanian devils. Pye and her team discovered the new, genetically-distinct DFTD cells in five devils from southern Tasmania, captured in 2014 and 2015. They named the cells DFT2, and the original strain DFT1.

Perhaps most interestingly, this cancer appears to be male, whereas the original DFT1 was female. "The original tumour found in 1996 was discovered in a female devil, whereas DFT2 was found in a handful of males," explains Tompkins. DFT1 cancer cells carry two X chromosomes, telling researchers that they originated in a female devil, whereas DFT2 cells have a Y chromosome, so must have come from a male.

We have also seen the tumour evolve

Cancers that can be transmitted between individuals are thought to be exceptionally rare in nature, and only a handful of cases have ever been identified, including DFTD, canine transmissible venereal tumour (CTVT), and a contagious reticulum cell sarcoma in Syrian hamsters.

The discovery of a second case in Tasmanian devils suggests that either contagious cancer is more common than we thought, or Tasmanian devils are unfortunately more prone to developing them than other species. Their low genetic diversity may be part of the reason for their vulnerability.

The discovery casts doubt over the future of the Tasmanian devil. Will their small, fragmented populations, barely able to fight off one contagious cancer, be able to cope with a second, to which they likely have no immunity? Or will DFT2 be the final nail in the devils' coffin? "The future impacts of DFT2 aren't exactly known," Tompkins says.

Belov says there is reason for optimism. "We have an amazing captive-breeding programme, which is now providing animals for release back into the wild. That is exciting."

Re-wilding the devil within mainland Australia would be an ideal step forward

But ongoing conservation work will be crucial to the devils' survival in the wild. "Devils would not survive in the wild without the active involvement of researchers, government agencies, zoos and wildlife parts and many others," says Belov.

"A successful vaccination trial, in addition to a significant population increase, would help to increase optimism for the Tasmanian devil in the future," Tompkins says. "Re-wilding the devil within mainland Australia would be an ideal step forward."

Although there may be light at the end of the tunnel for the unlucky Tasmanian devil, its future is far from certain. Its survival will depend on the delicate interplay between immunisation and release of captive-bred devils, naturally developing immunity in wild devils, and the spread of both facial cancers.

The coming few years may be crucial for the fate of these misunderstood creatures.

Join over six million BBC Earth fans by liking us on Facebook, or follow us on Twitter and Instagram.

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.