Background: Although previous studies suggested that rituximab increases the risk of Pneumocystis jirovecii pneumonia (PJP), it is uncertain whether its primary prophylaxis for PJP is justified. Research Question: Does the benefit of primary prophylaxis for PJP in patients receiving rituximab treatment outweigh the potential risk of the prophylaxis? Study Design and Methods: This retrospective study included 3,524 patients (hematologic diseases, 2,500; rheumatic diseases, 559; pre/post-solid organ transplantation, 465) first exposed to rituximab between 2002 and 2018 in a tertiary referral center in South Korea. Patients were classified into a control group (n = 2,523) and a prophylaxis group (n = 1,001) according to the administration of prophylactic trimethoprim-sulfamethoxazole (TMP-SMX) during the first 28 days after the start of rituximab (intention-to-treat analysis). In addition, exposure to TMP-SMX was examined as a time-varying variable (time-varying analysis). The primary outcome was the prophylactic effect of TMP-SMX on the 1-year incidence of PJP. Inverse probability of treatment weights was applied to minimize the baseline imbalance. The secondary outcome included the incidence of adverse drug reactions (ADRs) related to TMP-SMX. Results: Over 2,759.9 person-years, 92 PJP infections occurred, with a mortality rate of 27.2%. The prophylaxis group showed a significantly lower incidence of PJP (adjusted subdistribution hazard ratio, 0.20 [95% CI, 0.10-0.42]) than the control group. This result was consistent with the results of time-varying analysis, in which only one PJP infection occurred during TMP-SMX administration (adjusted subdistribution hazard ratio, 0.01 [0.003-0.16]). The incidence of ADRs related to TMP-SMX was 18.1 (14.6-22.2)/100 person-years, and most were of mild to moderate severity. On the basis of 10 severe ADRs, the number needed to harm was 101 (61.9-261.1), whereas the number needed to prevent one PJP infection was 32 (24.8-39.4). Interpretation: TMP-SMX prophylaxis significantly reduces PJP incidence with a tolerable safety profile in patients receiving rituximab treatment.