We describe the aetiology of community-acquired pneumonia (CAP) in HIV-infected patients, risk factors for bacterial or Pneumocystis jirovecii CAP and prognostic factors of 30-day mortality. This was a prospective observational study of 331 consecutive adult CAP cases in HIV-infected patients (January 2007 to July 2012). 128 (39%) patients had CD4+cell counts 200 per mm3and 99 (43%) ha HIV RNA levels 200 copies per mL on antiretroviral therapy. Streptococcus pneumoniae was the most frequent microorganism in the group with CD4+cell counts ≥200 per mm3; P. jirovecii was the most frequent microorganism in the group with CD4+cell counts 200 per mm3and in patients with HIV RNA ≥200 copies per mL. Predictors of bacterial CAP were: time with symptoms ≤5 days (OR 2.6, 95% CI 1.5-4.4), C-reactive protein level ≥22 mg·dL-1(OR 4.3, 95% CI 2.3-8.2) and hepatitis C virus co-infection (OR 2.3, 95% CI 1.4-3.9). White blood cell count ≤4×1012per L (OR 3.7, 95% CI 1.2-11.5), lactate dehydrogenase (LDH) level ≥598 U·L-1(OR 12.9, 95% CI 4.2-39.7) and multilobar infiltration (OR 5.8, 95% CI 1.9-19.5) were predictors of P. jirovecii . Overall 30-day mortality was 7%. Appropriate antibiotic treatment (OR 0.1, 95% CI 0.03-0.4), LDH ≥598 U·L-1(OR 6.2, 95% CI 1.8-21.8) and mechanical ventilation (OR 22.0, 95% CI 6.2-78.6) were the variables independently associated with 30-day mortality. The described predictors may help clinicians to distinguish between bacterial and P. jirovecii pneumonia in patients with suspected or confirmed HIV infection.