Scientists compared youngsters from a rural African village who had diets rich in fibre with another group living in Florence in Italy and found a dramatic difference.
The African children had less obesity-linked bacteria and a greater abundance of fatty acids which protect against inflammation causing asthma, eczema and other allergic reactions.
The diet of the children living in the small village of Boulon in Burkina Faso was similar to that of people living in the modern Western world thousands of years ago, shortly after the birth of agriculture.
It consisted mainly of cereals, beans, nuts and vegetables.
But the Italian children ate higher quantities of meat, fat and sugar.
Only those who were still breast-feeding harboured bacteria resembling the African children's - indicating diet may dominate other factors such as ethnicity, sanitation, geography or climate, say the researchers.
The trillions of microbes that inhabit the human gut are considered an essential 'organ' that helps to digest food, protect against disease-causing bugs and limit inflammation.
Paediatrician Dr Paolo Lionetti, of Florence University, and colleagues said children in industrialised countries who eat low-fibre, high-sugar 'Western' diets may reduce microbial richness - potentially contributing to a rise in allergic and inflammatory diseases in the last half-century.
They said: "Western developed countries successfully controlled infectious diseases during the second half of the last century, by improving sanitation and using antibiotics and vaccines.
"At the same time, a rise in new diseases such as allergic, autoimmune disorders, and inflammatory bowel disease (IBD) both in adults and in children has been observed, and it is hypothesized that improvements in hygiene together with decreased microbial exposure in childhood are considered responsible for this increase.
"The gastrointestinal microflora plays a crucial role in the pathogenesis of IBD and recent studies demonstrate obesity is associated with imbalance in the normal gut microbiota."
The researchers, whose findings are published in Proceedings of the National Academy of Sciences, added: "The lessons learned from the Burkina Faso children's microbiota prove the importance of sampling and preserving microbial biodiversity from regions where the effects of globalisation on diet are less profound.
"The worldwide diversity of the microbiome from ancient communities, where gastrointestinal infections can make the difference between life and death, represents a goldmine for studies aimed at elucidating the role of gut microbiota on the subtle balance between health and disease and for the development of novel probiotics."