To determine the relative contribution of patient non-adherence, provider failure to prescribe prophylaxis, and drug failure to the continued occurrence of Pneumocystis carinii pneumonia (PCP), and to determine correlates of non-adherence. Retrospective case-control study. Patients with confirmed or presumptive PCP from May 1995 to September 1997 who had at least 6 months of prior HIV care (cases) were compared to controls matched for initial CD4 cell count and date of initial HIV care. The incidence of PCP declined by 85% in the 28 months of the study. Of the 118 cases of PCP identified, 59 (50%) were in HIV care for > 6 months prior to PCP diagnosis. In a multivariate logistic regression model, risk factors for PCP among patients in HIV care were patient non-adherence [odds ratio (OR), 12.4; 95% confidence interval (CI), 6.4-23.5], use of prophylaxis other than trimethoprim-sulfamethoxazole (OR, 27.0; 95% CI, 13.8-52.9), and absence of antiretroviral use (OR, 7.5; 95% CI, 4.5-12.5). Provider non-adherence occurred in one out of 59 cases (2%), and five out of 106 controls (5%). Of the patients who developed PCP on prophylaxis, 18 cases (30%) appeared due to drug failure; there were no cases of apparent drug failure among patients on trimethoprim-sulfamethoxazole. In multivariate analysis, non-adherence was more common among patients of non-white race, those with a history of injecting drug use, and those with active substance abuse or psychiatric illness. Patient non-adherence was the most common reason for the occurrence of PCP among patients in HIV care; provider non-adherence was uncommon. Drug failure occurred only among patients on prophylaxis other than trimethoprim-sulfamethoxazole.