Two hundred eleven adults with human immunodeficiency virus (HIV) infection hospitalized for community-acquired pneumonia, including Pneumocystis carinii pneumonia (PCP; patients), and 192 matched HIV-infected hospitalized patients without pneumonia (controls) were interviewed to determine risk factors for pneumonia. Multivariate logistic regression showed that patients were less likely than controls to have used trimethoprim-sulfamethoxazole (TMP-SMZ) prophylaxis (odds ratio [OR], 0.22; 95% confidence interval [CI], 0.12-0.41) and more likely to have been hospitalized previously with pneumonia (OR, 6.25; CI, 3.40-11.5). Patients were also more likely than controls to have gardened (OR, 2.24; CI, 1.00-5.02) and to have camped or hiked (OR, 4.95; CI, 1.31-18.7), but stratified analysis by etiologic agent showed this association only for PCP. These findings reconfirm the efficacy of TMP-SMZ in preventing community-acquired pneumonia. In addition, hospitalization for pneumonia might represent a missed opportunity to encourage HIV-infected patients to enter into regular medical care and to adhere to prescribed antiretroviral and prophylaxis medications.