We establish a murine lung-on-chip infection model and use time-lapse imaging to reveal the dynamics of host-Mycobacterium tuberculosis interactions at an air-liquid interface with a spatiotemporal resolution unattainable in animal models and to probe the direct role of pulmonary surfactant in early infection. Surfactant deficiency results in rapid and uncontrolled bacterial growth in both macrophages and alveolar epithelial cells. In contrast, under normal surfactant levels, a significant fraction of intracellular bacteria are non-growing. The surfactant-deficient phenotype is rescued by exogenous addition of surfactant replacement formulations, which have no effect on bacterial viability in the absence of host cells. Surfactant partially removes virulence-associated lipids and proteins from the bacterial cell surface. Consistent with this mechanism, the attenuation of bacteria lacking the ESX-1 secretion system is independent of surfactant levels. These findings may partly explain why smokers and elderly persons with compromised surfactant function are at increased risk of developing active tuberculosis.