The safety and efficacy of sulfamethoxazole and trimethoprim in the prevention of Pneumocystis carinii pneumonia associated with the acquired immunodeficiency syndrome (AIDS) were evaluated. Sixty patients with a new diagnosis of Kaposi's sarcoma and no history of opportunistic infections were randomly assigned to receive 800 mg of sulfamethoxazole and 160 mg of trimethoprim twice per day or no therapy. None of the 30 patients receiving sulfamethoxazole and trimethoprim developed P carinii pneumonia. Sixteen of the 30 patients receiving no suppressive therapy developed P carinii pneumonia. Development of P carinii pneumonia was associated with the stage of Kaposi's sarcoma, B subtype disease, and the presence of 0.20 X 10(9)/L (200/mm3) or fewer CD4 cells at study entry. The proportion of patients surviving and the mean length of survival were significantly greater in the treatment group compared with the control group. Adverse reactions occurred in 15 patients (50%).