Having a dog in the family reduces a child's risk of asthma by 15%, and contact with farm animals can halve it, a large study has shown.
The findings lend strong support to the "hygiene hypothesis" that suggests living in too-clean conditions early in life can increase susceptibility to allergy conditions such as asthma.
Scientists analysed data on more than one million children born between 2001 and 2010 in Sweden, where dog and farm animal ownership has to be registered by law.
Dog exposure during the first year of life was associated with a 15% lower likelihood of childhood asthma, while living close to farm animals cut the risk by 52%.
Lead scientist Dr Tove Fall, from Uppsala University in Sweden, said: "Earlier studies have shown that growing up on a farm reduces a child's risk of asthma to about half.
"We wanted to see if this relationship also was true also for children growing up with dogs in their homes.
"Our results confirmed the farming effect, and we also saw that children who grew up with dogs had about 15% less asthma than children without dogs.
"Because we had access to such a large and detailed data set, we could account for confounding factors such as asthma in parents, area of residence and socio-economic status."
The research, published in the journal JAMA Pediatrics, was possible because of Sweden's organised system of national databases accessible by scientists.
Every visit to a specialist physician and every prescription is recorded.
Co-author Professor Catarina Almqvist Malmros, from Sweden's Karolinska Institute, said: "These kind of epidemiological studies look for associations in large populations but do not provide answers on whether and how animals could protect children from developing asthma.
"We know that children with established allergy to cats or dogs should avoid them, but our results also indicate that children who grow up with dogs have reduced risks of asthma later in life.
"Thanks to the population-based design, our results are generalisable to the Swedish population, and probably also to other European populations with similar culture regarding pet ownership and farming."
According to the hygiene hypothesis, lack of early exposure to microbes and parasites may prevent the immune system developing properly. As a result, natural checks on unwanted immune responses that can lead to allergy are lacking.
Erika Kennington, head of research at Asthma UK, said: "Asthma is a complex condition with many different types and causes.
"Whilst this study identifies a link to living with a dog or regular exposure to farm animals in the first year of a child's life, and their chance of developing asthma by the age of six, more research is needed.
"This will help us better understand the effects so that it can be turned into practical advice for parents of young children."