The discovery, made in mice, supports the idea that over-clean conditions early in life can set the stage for asthma and other allergy diseases.
According to the "hygiene hypothesis", some germ exposure is necessary to prime the developing immune system and keep it under control.
Further work could yield radical bacterial treatments for human infants aimed at preventing asthma, the scientists believe.
Other studies have already shown that airway exposure to bacteria can be "potently effective" at controlling allergy-driven airway inflammation in adult mice, they said.
The team led by Dr Benjamin Marsland, from the University of Lausanne in Switzerland, wrote in the journal Nature Medicine: "Our current study indicates that such treatments could be greatly optimised by targeting the narrow developmental window that exists following birth, or by targeting specific molecules.
"A key future step will be to translate these findings to human infants."
More than five million people in the UK are undergoing treatment for asthma, including 1.1 million children.
UK asthma rates are believed to have levelled off since the late 1990s but are still among the highest in Europe. In 2011 the condition claimed 1,167 lives in the UK, including 18 children aged 14 and under.
Asthma attacks are caused by an over-strong inflammatory immune response to allergy triggers such as house dust mites, pets or air pollutants.
The study showed that newborn mice were vulnerable to inflammation in the lungs when exposed to allergens. But over the first two weeks of life, colonisation of their lungs by bacteria led to the development of special immune cells with anti-asthma properties.
The regulatory T cells kept the immune system in check and suppressed the inflammation.
Interaction with a protein called PD-L1 was vital to the development of these cells, the researchers found. When PD-L1 was blocked, it had the same effect as keeping out the microbes - an exaggerated response to allergy triggers that persisted into adulthood.
"Overall, the concept of early developmental windows of allergic lung disease based on microbial colonisation represents a change in mainstream pathophysiological paradigms and presents unique opportunities for future post-natal modification of disease risk," the scientists concluded.