But consuming farm milk that hasn't been boiled poses serious health risks and further research is needed to develop a safe product that still provides good protection against these common childhood diseases.
Researchers from Europe and the USA studied 14,893 children aged between five and 13 in Austria, Germany, the Netherlands, Sweden and Switzerland.
The children were drawn from farm children, rural and suburban communities and Rudolph Steiner schools, which primarily cater for families with anthroposcopic lifestyles, who restrict their use of antibiotics, vaccinations, fever-reducing drugs and often follow a biodynamic diet.
Parents were asked to complete detailed questionnaires about their child's consumption of milk, butter, yoghurt, eggs and fruit and vegetables and whether they were farm-produced or shop-bought.
They also answered questions about their child's height and weight, whether they were breastfed and any allergies or asthma problems affecting the child or their family.
Allergy- related blood tests were also carried out on just under 4,000 children from across the five countries and the questionnaire results were validated with random telephone interviews with 493 respondents
The researchers discovered that children who drank farm milk were much less likely to suffer from hayfever and asthma.
Lower levels of diagnosed asthma were also observed for all farm-produced dairy products and eating farm eggs also provided protection against hayfever. However, these foods only provided increased protection when the children also drank unpasteurised farm milk - not in isolation.
None of the farm products had any effect on eczema levels.
"All the children drinking unpasteurised farm milk and eating other farm-related dairy products showed the same level of protection against asthma and allergies, regardless of whether they were living on a farm or not" says lead author Marco Waser, a doctor in natural sciences from the Institute of Social and Preventative Medicine at the University of Basel, Switzerland.
"This is an important finding as it rules out other protective factors that farm life may provide, such as exposure to microbial compounds in animal shed and farm homes. For example, earlier studies have shown that farm children are less likely to be affected by pollen.
"Our research showed that the children who enjoyed the best protection from asthma and allergies had been drinking farm milk since their first year of life."
About half of the parents who told researchers that their child regularly drank farm milk said that they did not boil the milk before giving it to them. The protective results were the same, regardless of whether milk was boiled or not.
However, as drinking raw milk is not recommended, especially for young children, this may have encouraged parents to say they boiled milk when they didn't, indicating a higher level of raw milk consumption.
"The results of this study indicate that all children drinking farm milk have a lower chance of developing asthma and hayfever" says Dr Waser.
"However raw milk may contain pathogens such as salmonella or enterohaemorrhagic E coli and its consumption may have serious health risks.
"We need to develop a deeper understanding of why farm milk offers children this higher level or protection and investigate ways of making the product safer, while retaining these protective qualities.
"At the moment we can only speculate about why farm milk protects children against asthma and allergies. Perhaps it is because farm milk has different levels or compositions of pathogenic and non-pathogenic microbes to milk sold in shops.
"It is interesting that there was no difference in the farm milk results regardless of whether it was boiled before consumption. As boiling is likely to have been over-reported, this could indicate that pasteurisation is not as important as previously thought, as compounds other than microbes may offer a protective role.
"But despite our findings, we cannot recommend consumption of raw farm milk as a preventative measure against asthma and allergies."
More than 35 researchers took part in the PARSIFAL study - Prevention of allergy risk factors for sensitisation in children related to farming and anthroposophic lifestyle. -Blackwell Publishing Ltd.