Multiple sclerosis (MS) is a heterogenous autoimmune disease in which autoreactive lymphocytes attack the myelin sheath of the central nervous system. B lymphocytes in the cerebrospinal fluid (CSF) of patients with MS contribute to inflammation and secrete oligoclonal immunoglobulins1,2. Epstein-Barr virus (EBV) infection has been epidemiologically linked to MS, but its pathological role remains unclear3. Here we demonstrate high-affinity molecular mimicry between the EBV transcription factor EBV nuclear antigen 1 (EBNA1) and the central nervous system protein glial cell adhesion molecule (GlialCAM) and provide structural and in vivo functional evidence for its relevance. A cross-reactive CSF-derived antibody was initially identified by single-cell sequencing of the paired-chain B cell repertoire of MS blood and CSF, followed by protein microarray-based testing of recombinantly expressed CSF-derived antibodies against MS-associated viruses. Sequence analysis, affinity measurements and the crystal structure of the EBNA1-peptide epitope in complex with the autoreactive Fab fragment enabled tracking of the development of the naive EBNA1-restricted antibody to a mature EBNA1-GlialCAM cross-reactive antibody. Molecular mimicry is facilitated by a post-translational modification of GlialCAM. EBNA1 immunization exacerbates disease in a mouse model of MS, and anti-EBNA1 and anti-GlialCAM antibodies are prevalent in patients with MS. Our results provide a mechanistic link for the association between MS and EBV and could guide the development of new MS therapies.