Background: We sought to clarify the association of HIV infection and immunodeficiency on myocardial infarction (MI) risk. Methods: We conducted a cohort study from 1996 to 2009 of HIV-positive (HIV+) and demographically matched HIV-negative (HIV-) Kaiser Permanente California health plan members. Rate ratios (RRs) were obtained from Poisson regression models comparing MI incidence rates between HIV+ (overall and stratified by recent and nadir CD4 count, and recent HIV RNA levels) and HIV- subjects, adjusting for age, sex, calendar era, race/ethnicity, census-based socioeconomic status, smoking, alcohol/drug abuse, overweight/obesity, diabetes, hypertension, and lipid-lowering therapy. Among HIV+ subjects, we also evaluated the independent association of CD4, HIV RNA, and antiretroviral therapy (ART) use. Results: The study population included 22,081 HIV+ and 230,069 HIV- subjects. The crude MI incidence rate per 100,000 person-years was 283 and 165 for HIV+ and HIV- subjects, respectively, with an adjusted RR of 1.4 [95% confidence interval (CI): 1.3 to 1.6]. Compared with HIV- subjects (reference), MI rates were similar for HIV+ subjects with recent CD4 >= 500 cells per microliter (RR = 1.18; 95% CI: 0.96 to 1.45) and those with nadir CD4 >= 500 cells per microliter (RR = 0.85; 95% CI: 0.55 to 1.33). Among HIV+ subjects, nadir CD4 was the only HIV-specific factor associated with MIs (RR per 100 cells = 0.88; 95% CI: 0.81 to 0.96), whereas recent CD4 and HIV RNA, prior ART use, and duration of protease inhibitors and nonnucleoside reverse transcriptase inhibitors were not associated with MIs. Conclusion: HIV+ subjects with recent or nadir CD4 >= 500 cells per microliter had similar MI rates compared with HIV- subjects. Lower nadir CD4, in particular, seems to be independently associated with MIs. These results strengthen recommendations for earlier ART initiation.