Media playback is unsupported on your device Media caption The greater Bermuda land snail is back from the brink

Thousands of critically endangered snails have been released into the wild after being rescued from the edge of extinction, with a little help from a British zoo.

The greater Bermuda land snail was thought to have disappeared for many years until an empty shell turned up in the territory's capital city, Hamilton.

Live snails were then found among litter in a nearby alleyway.

Some were flown to Chester Zoo for a unique breeding programme.

More than 4,000 snails raised at the zoo have now been taken back to the island and released.

Many more captive snails will soon be returned to their homeland to help give the species a new lease of life.

Mark Outerbridge, a wildlife ecologist for the Bermuda government, said the snail was a "Lazarus species", which was considered extinct not so long ago.

Then, in 2014, a man walked into his office in the capital, Hamilton, holding a fresh snail shell.

Image copyright Chester Zoo Image caption The snail measures about 2cm

"It turned out that, yes, this was in fact the greater Bermuda land snail, a species that we thought had gone extinct 40 years earlier," he said.

"He came back the next day with a fresh one, a live one in his hand, and that's how I was thrust into this conservation project."

A small but thriving population of land snails was discovered behind a restaurant. The gastropods were living among litter - specifically inside thrown-away plastic bags - in a "dank wet alley", surrounded by four-storey buildings.

Image copyright Mark Outerbridge Image caption The alleyway where the snails were rediscovered

Water dripping from air conditioning units had created an environment where the animals could survive unnoticed.

"It turned out that the plastic bags were one of the favourite places for these snails to hang out, because of course it retained the moisture the best - and the snails are very vulnerable to drying out," said Dr Outerbridge.

"And when we started picking up these plastic bags and unfolding them - literally they contained hundreds of juveniles and hatchling-sized snails."

Some of the hatchlings were taken into captivity for breeding. Their offspring were later sent to Chester Zoo and the Zoological Society of London, where scientists were able to establish colonies.

It turns out that the snails are prolific breeders in captivity, with thousands of snails bred in a matter of years.

Media playback is unsupported on your device Media caption Zookeeper Amber Flewitt with one of her charges

"At the last count we've got somewhere around 13,000 snails - we've probably got more than that, they've had a lot of babies since then," said Amber Flewitt, of Chester Zoo, who cares for the snails.

The secret of breeding success, she said, was nice soil and their favourite foods, which include sweet potato and lettuce.

Thousands of the Chester Zoo snails have now been sent back to Bermuda for release in nature reserves.

The snails are thought to be doing well in their new home.

Image copyright Chester Zoo Image caption The snails reproduce prolifically in captivity

Dr Gerardo Garcia of Chester Zoo said that, following three years of intensive work, the zoo was proud to see the snails heading home.

"This is an animal that has been on this planet for a very long time and we simply weren't prepared to sit back and watch them become lost forever when we knew we might be able to provide a lifeline," he said.

The greater Bermuda land snail is unique to Bermuda and is part of an ancient lineage of land snail that dates back in time over one million years.

Once abundant on the islands that make up the territory of Bermuda, the population went through a dramatic decline during the 20th Century after being preyed on by invading killer snails.

The snails have been released on a nature reserve on the northern Nonsuch Island, which has snail-friendly habitats and no evidence of the main predators that nearly caused the animal's demise.

They will join a small wild population, estimated at a few hundred individuals. This makes the species more rare in the wild than the likes of the giant panda or mountain gorilla, according to Chester Zoo.

Image copyright Chester Zoo Image caption A snail tagged so the population can be monitored for signs of recovery

Some captive individuals have been fitted with fluorescent tags to monitor their recovery in the wild.

"Not only did they escape the axe of extinction but they have rebounded so well in captivity through breeding that now what we're doing is we're identifying islands in Bermuda that don't have the predators and reintroducing them to those islands, and our expectations are very high that they'll do well," said Dr Outerbridge.

In the case of this species, it was a matter of having to look literally under every rock and every log before writing the animal off, he added.

Follow Helen on Twitter.