Respiratory surfaces are exposed to billions of particulates and pathogens daily. A protective mucus barrier traps and eliminates them through mucociliary clearance (MCC). However, excessive mucus contributes to transient respiratory infections and to the pathogenesis of numerous respiratory diseases. MUC5AC and MUC5B are evolutionarily conserved genes that encode structurally related mucin glycoproteins, the principal macromolecules in airway mucus. Genetic variants are linked to diverse lung diseases, but specific roles for MUC5AC and MUC5B in MCC, and the lasting effects of their inhibition, are unknown. Here we show that mouse Muc5b (but not Muc5ac) is required for MCC, for controlling infections in the airways and middle ear, and for maintaining immune homeostasis in mouse lungs, whereas Muc5ac is dispensable. Muc5b deficiency caused materials to accumulate in upper and lower airways. This defect led to chronic infection by multiple bacterial species, including Staphylococcus aureus, and to inflammation that failed to resolve normally. Apoptotic macrophages accumulated, phagocytosis was impaired, and interleukin-23 (IL-23) production was reduced in Muc5b(-/-) mice. By contrast, in mice that transgenically overexpress Muc5b, macrophage functions improved. Existing dogma defines mucous phenotypes in asthma and chronic obstructive pulmonary disease (COPD) as driven by increased MUC5AC, with MUC5B levels either unaffected or increased in expectorated sputum. However, in many patients, MUC5B production at airway surfaces decreases by as much as 90%. By distinguishing a specific role for Muc5b in MCC, and by determining its impact on bacterial infections and inflammation in mice, our results provide a refined framework for designing targeted therapies to control mucin secretion and restore MCC.