Reputation: Dung beetles roll across the African savannah with big balls of, well, dung. The ancient Egyptians were really into them, for some reason.

Reality: From South America to South Africa, the UK to the USA, they will be there. Not only are dung beetles a diverse and multifaceted group of insects, they keep our farmland fertile and our pests and parasites at bay, and even play a part in reducing greenhouse gas emissions. They do not all eat dung, either.

The dung beetle was an icon in ancient Egypt, adorning temples, jewellery and texts. It was the symbol of a god who rolled the Sun up over the horizon each day, just like an enormous ball of dung. To this day, this is the stereotypical dung beetle, the one made famous by natural history films – a stocky black insect, trundling along with its smelly ball.

"I get that a lot," says insect ecologist Tomas Roslin at the Swedish University of Agricultural Sciences, "and then hurry to point out that there are as many different species of beetles living in dung as there are, for example, bird species globally".

The sacred scarab of Egypt is a real animal, but it is just the tip of the dung heap. Dung beetles can be big or small, adorned with beautiful colours or horns to fight opponents, and inhabit chilly grasslands or tropical rainforests. Of the thousands of dung beetle species, only a fraction actually roll their dung into balls, and many do not eat dung at all.

"With so many different species that exist globally, the differences in life history are almost endless," says Trond Larsen, a tropical ecologist and Director of Conservation International's Rapid Assessment Program. "Among the most fascinating dung beetle species are those which have developed unusual specialisations."

Most dung beetles work hard to live up to their name. In their quest for dung, some species engage in epic kung fu battles on the savannah. Others take up residence by monkeys' anuses, so they can hop onto the dung as it leaves its owner: a perfect example of "first come, first serve".

But according to Larsen, it is common to find over 150 distinct dung beetle species at a single site in the tropics. With this level of competition for limited quantities of dung, it is hardly surprising that some have evolved non dung-based diets.

These diets would still not be to everyone's taste. Whether it is carrion, rotting fruit and fungi, or dead invertebrates, dung beetles seem happy to serve as nature's bin men, hoovering up unpleasant detritus and waste. One species lives on the backs of giant land snails, sucking up their mucus while enjoying a free ride.

Perhaps the most fascinating specialists are the dung beetles that have made the switch from dung to hunting prey.

Predatory dung beetles have long been alluded to in the scientific literature. One species from Brazil was recorded decapitating large ants, before leaving their heads behind and rolling the fat abdomens into an underground lair – as if they were balls of dung.

Most of all, though, some dung beetles really seem to have it in for millipedes.

Aware of reports that certain beetles attack live millipedes, Larsen decided to go in search of the killer. After identifying a likely Peruvian species called Deltochilum valgum, he captured some specimens to observe their behaviour. "I was amazed to unravel the highly detailed attack strategies employed by the beetles," he enthuses. Once again, decapitation is their favoured mode of attack.

However, thanks to their family history of eating dung, these beetles lack the sharp mouthparts commonly found in carnivorous animals. Instead, they have to improvise.

"Successful decapitation of millipedes depends on a suite of morphological adaptations, such as the shape of the hind legs, the prying 'teeth' on the front of the head, and the narrow width of the head for fitting inside the millipede's body segments," says Larsen. Essentially, the dung beetles slowly prise their unfortunate prey's body apart.

Millipedes are commonplace and slow, making them the perfect prey for these makeshift predators. Larsen reckons the evolutionary leap from feeding on carrion and dead invertebrates to living millipedes is not huge, and predicts that other dung beetles will also make the switch.

Clarke Scholtz, a veteran entomologist at the University of Pretoria in South Africa, knows a thing or two about dung beetles. He says that millipede-eaters are also present across the Atlantic, and agrees that this lifestyle change is actually rather straightforward.

"Adult dung beetles are not dung feeders in the strictest sense of the word," says Scholtz. "They feed on tiny particles of gut epithelium from whatever it was that produced the dung, bacteria, fungi and tiny fractions of dung."

Meanwhile, carrion-feeding dung beetles, and those feeding on invertebrates, are slurping on smoothies of juices and insides, filtering out the nutritious particles just as they would with dung.

Despite their forays into other foodstuffs, the primary business of the dung beetle family is still, well, "business". Whether they roll it around, bury it or live inside it, these beetles know their way around a pile of poop, and have done since the time of the dinosaurs.

What's more, while they are not pushing the Sun across the sky, dung beetles are doing important work.

"Dung beetles are an essential part of the ecosystem," says Bryony Sands of the University of Bristol, UK. "In my opinion, they are as important as bees, but because of their unglamorous lifestyle their value is definitely overlooked."

Faeces are a fact of life, and without an efficient waste disposal system the world would quickly descend into a swamp of unprocessed sewage. Dung beetles are that system. "The beetles process the dung by tunnelling, burying, and fragmenting it," says Sands. They lay their eggs in it, their larvae eat it, worms bury it further, and the circle of dung continues.

Scholtz puts the situation into perspective. "We have 15 million cattle in South Africa, and each produces about 12 cow pats per day," he says. "That equates to about 5,500 tonnes of dung every day. We would all be knee deep – or shoulder deep – in it if it wasn't for dung beetles." And that is before we even consider the elephant dung.

"This whole process not only quickly and efficiently removes dung from the surface, it brings all those important nutrients back down into the soil, making the soil fertile and our pastures productive," says Sands.

In the UK, which is home to a mere 60 species of dung beetle compared to South Africa's 800, the ecosystem services provided by dung beetles could be saving the cattle industry £367 million each year. Comparable savings have been estimated in the USA. Not only are dung beetles boosting pasture fertility, they also disperse seeds, improve soil structure, and reduce the prevalence of pests and parasites that affect both humans and livestock.

In a 2016 study, Sands showed that dung beetles reduce the spread of intestinal worms in cattle. Unfortunately, the anti-worm drugs farmers give to their cattle come out in their dung, and that is bad news for the beetles. "This is a bit of a catch-22," says Sands. "The very chemicals that farmers are using to treat the gut worms are actually killing the dung beetles, which would be naturally reducing worm transmission on pasture, making the problem worse in the long run."

Indeed, the tremendous value of dung beetles has not gone unnoticed. Some pioneering scientists have used them to orchestrate major ecological changes.

The most dramatic instance of dung beetle intervention began in Australia in the 1960s, when the country was facing a dung disaster. Native dung beetles were used to the dry, hard dung of marsupials, not the sloppy pats left by introduced cattle. This led to farmlands covered with cow dung and bush fly swarms of biblical proportions.

In a bold move, the Commonwealth Scientific and Industrial Research Organisation (CSIRO) established the Australian Dung Beetle Project. Over two decades, a team introduced 53 species of dung beetles from around the world. The foreign beetles were able to beat back the tide of manure, leading to a drop of about 90% in bush fly numbers. As a side note, it has been argued that the decline in flies has also saved the country's outdoor cafés from extinction.

Such was the success of the project that it has been repeated both in Australia and in neighbouring New Zealand, and this is not the final word on dung beetle interventions. "CSIRO and other Australian and New Zealand researchers have not concluded their efforts in the dung beetle space," says Patrick Gleeson, a research technician at CSIRO. He mentions a recent application to develop a new, national dung beetle project.

To add to a growing list of dung beetle powers, work by Roslin and his colleagues has also found evidence that dung beetles can reduce greenhouse gas emissions.

"We are talking fairly big effects, like a reduction of 40% of total methane emissions from any single dung pat inhabited by beetles," Roslin says. "Dung beetle tunnels will serve as ventilation shafts, bringing oxygen into the pat. That will shift the balance between different microbes. Methane-producing microbes don't like oxygen."

When you consider the emissions from an entire food supply chain, Roslin says, the impact of beetles is relatively small. Nevertheless, this addition to dung beetles's CV is yet another reminder of their significance.

In Finland, where Roslin conducted his studies, the tiny beetles are a far cry from the ostentatious, mouse-sized creatures found in Africa. But they are still playing their role, epitomising the biologist E.O. Wilson's reference to "the little things that run the world".

"Remember, dung beetles are not just something you see struggling with balls of elephant dung on African savannahs," says Sands. "They are right here at home on your doorstep, and they need to be looked after!"