A new low-tech solution is helping eliminate an age-old problem in northern Tanzania – the conflict between predators and farmers.

Lions raid Masai cattle in the villages, and then the herders kill lions in retribution. Lion numbers in the region have declined by 50% since 2003 as a result of killings by villagers, as well as habitat fragmentation and loss.

But that trend is now being reversed by a new kind of pen, known as a living wall, which is keeping livestock safe from attacks by big cats, and the cats safe from Masai spears. About 360 of these lion-proof fences have already been built in the Masai steppe region over the past five years.

Masai men erect a living wall fence in Tanzania. The fence is partly made with African myrrh tree wood that creates an impenetrable barrier. Photograph: Deirdre Leowinata

There have been no lion attacks, says Dr Laly Lichtenfeld, in any of the villages where these fences have been installed. Lichtenfeld is the executive director of the African People and Wildlife Fund, the US-funded charity which is sponsoring the Living Wall project.

The project leader, Elvis Kisimir, supervises a crew of Masai warriors. The young men hammer in a chain link fencing to seal the gaps between posts hewn from African myrrh or Commiphora Africana trees. Many of these posts look dead, but some have already sprouted twigs and tender young leaves. As the trees continue to grow, their interlocked crowns create an impenetrable barrier, which, unlike chain link alone, cannot be scaled by leopard and small lion, and their root system prevents hyenas from tunnelling in from below.

Traditionally, the Masai have built bomas – livestock enclosures out of the branches of thorny acacia trees to protect their animals from predators. These rough hewn barriers, however, deteriorate quickly and are relatively easy for predators to penetrate during their nocturnal hunts. The living walls, by contrast, last a very long time and cannot be breached.

Lichtenfeld's research indicates that, as a result of these tree-fences, there are far fewer human attacks on lions today than there were a decade ago in the area of more than 5,000 sq km where the living walls have been introduced. She has documented that in communities where an average of six or seven lions had been killed in retaliation attacks a year, after the new natural fences are installed, that number falls to an average of less than one. Living walls have now been built in 12 communities, and there is a long list of villages waiting for installation.

The project is allowing the lion population to gradually recover, says Lichtenfeld: "In the past couple of years, we've documented in our camera trap data larger prides of females, more cubs and sub-adults, healthier and bigger lions – all signs that lion numbers are beginning to rebound."

Elsewhere in Africa the big cats are not faring so well. Lion numbers have been declining throughout the continent, and the species has now vanished from 80% of its historical range. Only a few hundred individuals remain in the whole of west Africa, and elsewhere in Africa there are at best 35,000 lions left, down from over 100,000 fifty years ago.