It is not often that an animal that eats you turns out to be your saviour, but that is exactly the strange relationship between pine martens and red squirrels, according to scientists.

According to a new study, pine martens prefer to eat grey squirrels, the red's great rival. So much so, that populations of the greys crash if pine martens are about, while their red cousins thrive.

Grey squirrels are fatter and slower than the nimble reds, so make a more attractive and easier meal for the martens, which are known to be ferocious and opportunistic predators.

Greys, introduced from North America in the 19th century, have squeezed out the native reds by eating their food and giving them a fatal pox. As a result, reds are now at risk of extinction, with only 121,000 left in Scotland. Wildlife groups have banded together to try to save the reds by trapping, killing and shooting thousands of greys. But now they say they have a new friend in the pine marten.

Martens were once persecuted to the verge of extinction, but under legal protection have been recovering in recent decades. They are now established in large parts of Scotland north of the central belt, with an adult population of around 3000.

A major study published in the scientific journal Biodiversity And Conservation has concluded that the spread of pine martens could be a "critical factor" in the success or failure of grey squirrels. A survey of over 9000 square kilometres in central Ireland found red squirrels became common and greys suffered a "population crash" in areas where pine martens were active.

The study's authors, Emma Sheehy and Colin Lawton from the National University of Ireland, suggested their findings could apply to Scotland, and "could prove highly significant in terms of red squirrel conservation".

The Scottish Wildlife Trust, one of the groups working to protect red squirrels, said it was delighted pine martens were making a comeback.

Jonny Hughes, the trust's conservation director, said: "Evidence from Ireland that pine marten predation on grey squirrels can significantly reduce their numbers and thereby help the expansion of red squirrels is increasingly compelling."

Hughes said pine martens and red squirrels had evolved together, so the squirrels have worked out how to avoid getting caught.

However, the Government's wildlife agency, Scottish Natural Heritage, was more cautious. Its mammal expert, Rob Raynor, said: "The Irish evidence shows there may be a link, albeit a strong link, between pine marten expansion and grey squirrel abundance, but we're not aware of any evidence that shows a clear cause and effect.

"Without this, we feel it would be premature to draw firm conclusions on the practical applications in Scotland and elsewhere. But we will keep a close eye on any future research."