The coronavirus disease 2019 (COVID-19) pandemic and lockdowns prompted a major concern for mental health effects. Comprehensive nationwide studies are lacking on the indirect effect of the COVID-19 pandemic on the mental health of the population. We aimed to determine whether the COVID-19 pandemic and lockdowns affected mental health service usage, suicide attempts and suicides. This comprehensive nationwide register-linked study followed all individuals in Denmark from 1990. The main outcomes were rates of psychiatric admissions, use of psychotropic medication, suicide attempts, suicides, patients in community-based private psychiatry or psychology practices and referrals to psychiatric hospitals. The impact of the pandemic (11 March 2020-30 June 2023) and lockdowns was assessed with log-normal models adjusted for pre-pandemic trends (1 January 2017-10 March 2020). We reported rate ratios (RR) of the observed and counterfactual rates. We identified the 5 807 714 (50.3% female) individuals living in Denmark on 1 March 2020. The rates of psychiatric admissions [RR: 0.95, 95% confidence interval (CI): 0.91 to 0.99, P-value: 0.017] and suicide attempts (RR: 0.85, 95% CI: 0.76 to 0.95, P-value: 0.007) were lower during the pandemic compared with the pre-pandemic trend. The rates of suicides (RR: 0.89, 95% CI: 0.75-1.05, P-value: 0.173), patients in private practices (RR: 1.00, 95% CI: 0.96-1.04, P-value: 0.986) and referrals (RR: 1.06, 95% CI: 0.95-1.18, P-value: 0.307) were not significantly different during the pandemic compared with the pre-pandemic trend. During the first lockdown, rates were lower for psychiatric admissions (RR: 0.85, 95% CI: 0.80 to 0.90, P-value <0.001), suicide attempts (RR: 0.80, 95% CI: 0.69 to 0.94, P-value: 0.007), suicides (RR: 0.67, 95% CI: 0.52 to 0.86, P-value: 0.002), patients in private practices (RR: 0.88, 95% CI: 0.82 to 0.93, P-value <0.001) and referrals (RR: 0.69, 95% CI: 0.60 to 0.81, P-value <0.001) compared with the pre-pandemic trend. However, during the pandemic, the rate of psychotropic medication users increased by 6% compared with the pre-pandemic trend (RR: 1.06, 95% CI: 1.05 to 1.06, P-value < 0.001). The COVID-19 pandemic and lockdowns did not severely influence pre-pandemic trends of the mental health burden in the population of Denmark on a nationwide level.