The primary function of type II pneumocytes is the production and secretion of pulmonary surfactant. Surfactant is a lipoprotein complex that reduces surface tension within the alveoli, preventing alveolar collapse during exhalation. In addition to their role in surfactant production, type II pneumocytes also serve as progenitor cells for type I pneumocytes, aiding in the repair and regeneration of the alveolar epithelium following injury.