The association between coffee intake and risk of myocardial infarction (MI) remains controversial. Coffee is a major source of caffeine, which is metabolized by the polymorphic cytochrome P450 1A2 (CYP1A2) enzyme. Individuals who are homozygous for the CYP1A2*1A allele are "rapid" caffeine metabolizers, whereas carriers of the variant CYP1A2*1F are "slow" caffeine metabolizers. To determine whether CYP1A2 genotype modifies the association between coffee consumption and risk of acute nonfatal MI. Cases (n = 2014) with a first acute nonfatal MI and population-based controls (n = 2014) living in Costa Rica between 1994 and 2004, matched for age, sex, and area of residence, were genotyped by restriction fragment-length polymorphism polymerase chain reaction. A food frequency questionnaire was used to assess the intake of caffeinated coffee. Relative risk of nonfatal MI associated with coffee intake, calculated using unconditional logistic regression. Fifty-five percent of cases (n = 1114) and 54% of controls (n = 1082) were carriers of the slow *1F allele. For carriers of the slow *1F allele, the multivariate-adjusted odds ratios (ORs) and 95% confidence intervals (CIs) of nonfatal MI associated with consuming less than 1, 1, 2 to 3, and 4 or more cups of coffee per day were 1.00 (reference), 0.99 (0.69-1.44), 1.36 (1.01-1.83), and 1.64 (1.14-2.34), respectively. Corresponding ORs (95% CIs) for individuals with the rapid *1A/*1A genotype were 1.00, 0.75 (0.51-1.12), 0.78 (0.56-1.09), and 0.99 (0.66-1.48) (P = .04 for gene x coffee interaction). For individuals younger than the median age of 59 years, the ORs (95% CIs) associated with consuming less than 1, 1, 2 to 3, or 4 or more cups of coffee per day were 1.00, 1.24 (0.71-2.18), 1.67 (1.08-2.60), and 2.33 (1.39-3.89), respectively, among carriers of the *1F allele. The corresponding ORs (95% CIs) for those with the *1A/*1A genotype were 1.00, 0.48 (0.26-0.87), 0.57 (0.35-0.95), and 0.83 (0.46-1.51). Intake of coffee was associated with an increased risk of nonfatal MI only among individuals with slow caffeine metabolism, suggesting that caffeine plays a role in this association.