BACKGROUND: Neurological and psychiatric sequelae of COVID-19 have been reported, but more data are needed to adequately assess the effects of COVID-19 on brain health. We aimed to provide robust estimates of incidence rates and relative risks of neurological and psychiatric diagnoses in patients in the 6 months following a COVID-19 diagnosis. METHODS: For this retrospective cohort study and time-to-event analysis, we used data obtained from the TriNetX electronic health records network (with over 81 million patients). Our primary cohort comprised patients who had a COVID-19 diagnosis; one matched control cohort included patients diagnosed with influenza, and the other matched control cohort included patients diagnosed with any respiratory tract infection including influenza in the same period. Patients with a diagnosis of COVID-19 or a positive test for SARS-CoV-2 were excluded from the control cohorts. All cohorts included patients older than 10 years who had an index event on or after Jan 20, 2020, and who were still alive on Dec 13, 2020. We estimated the incidence of 14 neurological and psychiatric outcomes in the 6 months after a confirmed diagnosis of COVID-19: intracranial haemorrhage; ischaemic stroke; parkinsonism; Guillain-Barré syndrome; nerve, nerve root, and plexus disorders; myoneural junction and muscle disease; encephalitis; dementia; psychotic, mood, and anxiety disorders (grouped and separately); substance use disorder; and insomnia. Using a Cox model, we compared incidences with those in propensity score-matched cohorts of patients with influenza or other respiratory tract infections. We investigated how these estimates were affected by COVID-19 severity, as proxied by hospitalisation, intensive therapy unit (ITU) admission, and encephalopathy (delirium and related disorders). We assessed the robustness of the differences in outcomes between cohorts by repeating the analysis in different scenarios. To provide benchmarking for the incidence and risk of neurological and psychiatric sequelae, we compared our primary cohort with four cohorts of patients diagnosed in the same period with additional index events: skin infection, urolithiasis, fracture of a large bone, and pulmonary embolism. FINDINGS: Among 236 379 patients diagnosed with COVID-19, the estimated incidence of a neurological or psychiatric diagnosis in the following 6 months was 33·62% (95% CI 33·17-34·07), with 12·84% (12·36-13·33) receiving their first such diagnosis. For patients who had been admitted to an ITU, the estimated incidence of a diagnosis was 46·42% (44·78-48·09) and for a first diagnosis was 25·79% (23·50-28·25). Regarding individual diagnoses of the study outcomes, the whole COVID-19 cohort had estimated incidences of 0·56% (0·50-0·63) for intracranial haemorrhage, 2·10% (1·97-2·23) for ischaemic stroke, 0·11% (0·08-0·14) for parkinsonism, 0·67% (0·59-0·75) for dementia, 17·39% (17·04-17·74) for anxiety disorder, and 1·40% (1·30-1·51) for psychotic disorder, among others. In the group with ITU admission, estimated incidences were 2·66% (2·24-3·16) for intracranial haemorrhage, 6·92% (6·17-7·76) for ischaemic stroke, 0·26% (0·15-0·45) for parkinsonism, 1·74% (1·31-2·30) for dementia, 19·15% (17·90-20·48) for anxiety disorder, and 2·77% (2·31-3·33) for psychotic disorder. Most diagnostic categories were more common in patients who had COVID-19 than in those who had influenza (hazard ratio [HR] 1·44, 95% CI 1·40-1·47, for any diagnosis; 1·78, 1·68-1·89, for any first diagnosis) and those who had other respiratory tract infections (1·16, 1·14-1·17, for any diagnosis; 1·32, 1·27-1·36, for any first diagnosis). As with incidences, HRs were higher in patients who had more severe COVID-19 (eg, those admitted to ITU compared with those who were not: 1·58, 1·50-1·67, for any diagnosis; 2·87, 2·45-3·35, for any first diagnosis). Results were robust to various sensitivity analyses and benchmarking against the four additional index health events. INTERPRETATION: Our study provides evidence for substantial neurological and psychiatric morbidity in the 6 months after COVID-19 infection. Risks were greatest in, but not limited to, patients who had severe COVID-19. This information could help in service planning and identification of research priorities. Complementary study designs, including prospective cohorts, are needed to corroborate and explain these findings. FUNDING: National Institute for Health Research (NIHR) Oxford Health Biomedical Research Centre.