The primary function of PEEP is to maintain alveolar recruitment and improve gas exchange. By preventing alveolar collapse, PEEP enhances functional residual capacity (FRC), which is the volume of air remaining in the lungs after a normal expiration. This mechanism is vital in avoiding atelectasis, a condition where parts of the lung are collapsed, leading to impaired oxygenation.