Background: The inconsistency of previous reports examining cognitive function in obsessive-compulsive disorder (OCD) suggests its heterogeneity. In this study, we examined the effect of illness duration on cognitive function in OCD. Methods: We examined the cognitive function of 32 OCD patients and 16 healthy volunteers by neuropsychological tests and functional magnetic resonance imaging while they performed the Stroop and N-back tasks to assess attention and nonverbal memory. The patients were divided into two groups by illness duration: a short-term group (n = 17, 5.5 +/- 3.1 years) and a long-term group (n = 15, 20.3 +/- 6.1 years). Statistical analysis was performed to determine the differences between these two groups and the normal control group (n = 16). Results: The long-term group showed attention deficit and nonverbal memory dysfunction on the neuropsychological tests. In contrast, on functional magnetic resonance imaging, the short-term group showed weaker activation of the right caudate during the Stroop task and stronger activation of the right dorso-lateral prefrontal cortex during the N-back task than the long-term and normal control groups. Conclusions: The results suggested that abnormal brain activation occurs in the early phase of OCD and that the long-term persistence of OCD might involve a decline in cognitive function. Depression and Anxiety 26:814-823, 2009. (C) 2008 Wiley-Liss, Inc.