The few studies that have examined the association between usual sleep duration and cognitive function have shown conflicting results. This cross-sectional study examined the association between sleep duration and cognitive function among 3212 people, representative of the non-institutionalized population aged 60 years and over in Spain. Sleep duration was self-reported, and cognitive function was measured with the Mini-Examen Cognoscitivo (MEC), a version of the Mini-Mental State Examination that has been validated in Spain. Linear regression, with adjustment for the main confounders, was used to obtain mean differences in the MEC between the categories of sleep duration (≤5, 6, 7, 8, 9, 10, ≥11 h day−1). The MEC score decreased progressively (became worse) across sleep categories from 7 to ≥11 h (P for linear trend <0.001). People who slept for ≥11 h had a significantly lower MEC score than those who slept for 7 h (mean difference −1.48; 95% confidence interval −2.12 to −0.85). This difference in the MEC was similar to that observed for a 10-year increase in age. The results did not vary significantly by sex (P for interaction >0.05). No association was observed between short sleep duration (<7 h) and cognitive function. We conclude that long sleep duration is associated with poorer cognitive function in older adults from the general population.