Pneumocystis pneumonia constitutes a critical life-threatening opportunistic infection, where the host's immune response plays a central role in its pathogenesis. Immunocompetent individuals are typically capable of eradicating Pneumocystis without exhibiting clinical symptoms. In contrast, individuals with compromised immune systems are vulnerable to developing Pneumocystis pneumonia, which can lead to severe inflammatory responses and consequent pulmonary damage. This review examines the roles of innate immunity, particularly macrophages and adaptive immunity, including CD4 + and CD8 + T-cells, as well as key cytokines, in the defence against Pneumocystis infection across various host categories, namely immunocompetent individuals, those infected with HIV and non-HIV-infected individuals, especially those undergoing corticosteroid therapy. By integrating findings from animal models and clinical studies, this review seeks to enhance our understanding of the pathogenesis of Pneumocystis infection across varied immunological contexts.