To compare the clinical efficacy and safety of trimethoprim-sulfamethoxazole (TMP-SMX) with pentamidine in the therapy of Pneumocystis carinii pneumonia (PCP) in patients with AIDS. TMP-SMX (TMP, 20 mg/kg/day plus SMX, 100 mg/kg/day) was compared with pentamidine (4 mg/kg/day), both administered intravenously for 21 days in a prospective randomized treatment trial of 163 patients diagnosed with PCP between November 1984 and May 1988. Ninety-two evaluable patients received TMP-SMX as initial therapy; 68 received pentamidine. Failure to complete therapy was common. Of those receiving TMP-SMX, 39 (42%) required change in therapy because of failure to respond, and an additional 31 (34%) because of drug toxicity. This compared with 27 (40%; P = 0.733) and 17 (25%; P = 0.235), respectively, in the pentamidine-treated group. The overall survival rates were similar in the two groups, 62 out of 92 (67%) initially administered TMP-SMX versus 50 out of 68 (74%) initially administered pentamidine (P = 0.402). The survival rates for patients requiring a change in therapy because of failure to respond was 46% (18 out of 39) for the TMP-SMX group compared with 56% (15 out of 27) for the pentamidine group. When a change in therapy was made because of toxicity, survival rates were 97% (30 out of 31) for those receiving TMP-SMX versus 94% (16 out of 17) for those receiving pentamidine. TMP-SMX and pentamidine are of equivalent efficacy as initial therapies for PCP in patients with AIDS.