Cocaine passes the placental and fetal brain barriers and directly affects the developing brain. The few prospective studies reported that examined the long-term cognitive effects of prenatal cocaine exposure have given inconsistent results. The present trial was a prospective, longitudinal, blind comparison cohort study assessing the effects of in utero cocaine exposure and the quality of caregiving on cognitive function at age 4 years. Of 415 consecutively enrolled infants, all from a high-risk population, 376 (190 cocaine-exposed and 186 unexposed) were available for evaluation at age 4 using the Wechsler Preschool and Primary Scales of Intelligence-Revised. Caregivers completed the Home Observation of the Environment (HOME)-Preschool version that assesses the quality of the caregiving environment. A majority of women were low-income blacks. Cocaine users were older than nonusers, had more children, and were less likely to have received prenatal care. They also were less likely to be married and to have completed high school, and they experienced more psychologic distress. Cocaine users also used alcohol, tobacco, and marijuana more often (and in greater amounts) than nonusers of cocaine. Exposed infants were of lower gestational age, birth weight, length, and head circumference than unexposed infants. They were likelier than unexposed infants to be preterm, small for gestational age, and in nonmaternal care. Controlling for covariables, prenatal cocaine exposure was not associated with lower full-scale IQ scores or summary verbal IQ stores at age 4 years. It did, however, predict small but significant deficits in visual-spatial skills, general knowledge, and arithmetic skills. Children exposed to cocaine before birth were less likely to achieve an IQ above the normative mean. Exposed children in nonrelative foster or adoptive care lived in more stimulating environments and had IQ scores comparable to those of unexposed children who were in biologic maternal or relative care. Their scores were higher than those of cocaine-exposed children in biologic maternal or relative care. The latter children had lower full-scale and performance IQ scores than did unexposed children. The quality of the caregiving environment was the strongest independent predictor of cognitive outcomes. These findings are in accord with those from other studies of preschool cocaine-exposed children that identified specific but not global IQ deficits. Cocaine-exposed children do better cognitively when living in a favorable home environment.