BACKGROUND: Several risk factors for suicide have been identified. We assessed the relative risks and population attributable risks of suicide associated with various socioeconomic factors and with previous mental illness that necessitated hospital admission. Our aim was to assist in the choice of potential strategies for preventing suicide in the general population. METHODS: We did a population-based nested case-control study based on register data. Data were collected on a random 5% sample of the Danish population aged 16-78 years during a 15-year period (1980-94) and analysed with conditional logistic regression. FINDINGS: 811 cases of suicide were found and 79871 controls were chosen in this population. Unemployment, low income, being single, and a history of mental illness necessitating hospital admission were associated with increased risk of suicide. However, in the multivariate analysis, the strongest risk factor was mental illness necessitating hospital admission; risk of suicide was especially high during admission (relative risk 62.6 [95% CI 41.1-95.4]) and during the year after discharge (6.51 [5.03-8.44]). The effect of socioeconomic variables decreased after adjustment for history of mental illness. The population attributable risk associated with mental illness necessitating admission to hospital was 44.6% (43.6-45.5); the attributable risks associated with the other factors were 3.0% (1.4-6.6) for unemployment and 10.3% (6.13-16.9) for being single. INTERPRETATION: Suicide prevention aimed at patients who are admitted to hospital with mental disorders and improved detection and treatment of mental disorders in the general population may be the most efficient strategy to decrease risk of suicide. Reports of high relative risk and attributable risk associated with unemployment and other socioeconomic risk factors may be confounded and overestimated owing to the lack of adjustment for the association with mental disorders.