Respiratory dysfunction is a notorious cause of perinatal mortality in infants and sleep apnoea in adults, but the mechanisms of respiratory control are not clearly understood. Mechanical signals transduced by airway-innervating sensory neurons control respiration; however, the physiological significance and molecular mechanisms of these signals remain obscured. Here we show that global and sensory neuron-specific ablation of the mechanically activated ion channel Piezo2 causes respiratory distress and death in newborn mice. Optogenetic activation of Piezo2+ vagal sensory neurons causes apnoea in adult mice. Moreover, induced ablation of Piezo2 in sensory neurons of adult mice causes decreased neuronal responses to lung inflation, an impaired Hering-Breuer mechanoreflex, and increased tidal volume under normal conditions. These phenotypes are reproduced in mice lacking Piezo2 in the nodose ganglion. Our data suggest that Piezo2 is an airway stretch sensor and that Piezo2-mediated mechanotransduction within various airway-innervating sensory neurons is critical for establishing efficient respiration at birth and maintaining normal breathing in adults.