This study examined the factors associated with the development of a first episode of Pneumocystis carinii pneumonia (PCP) in 5,025 patients with AIDS, including 1,976 patients with primary PCP at the time of AIDS diagnosis and 635 with primary PCP occurring subsequently. Compared with untreated patients, patients treated with zidovudine were at similar risk of developing PCP during the first year of therapy but were at greater risk after longer intervals of treatment. The following factors were associated with an increased risk of PCP (either at the time of AIDS diagnosis or thereafter): lack of primary PCP prophylaxis, male homosexuality/bisexuality, diagnosis of AIDS in northern Europe, and CD4 cell count below 200 x 10(6)/L at the time of AIDS diagnosis. Patients with severe weight loss had a 60% higher risk of developing PCP during follow-up than those without such weight loss. Thus, the occurrence of PCP depended on geographic location, mode of acquisition of human immunodeficiency virus and AIDS, degree of immunodeficiency, and use of various treatment regimens.