Epidemiological studies have provided compelling evidence that multiple sclerosis (MS) is a rare complication of infection with the Epstein–Barr virus (EBV), a herpesvirus that infects more than 90% of the global population. This link was long suspected because the risk of MS increases markedly after infectious mononucleosis (symptomatic primary EBV infection) and with high titres of antibodies to specific EBV antigens. However, it was not until 2022 that a longitudinal study demonstrated that MS risk is minimal in individuals who are not infected with EBV and that it increases over 30-fold following EBV infection. Over the past few years, a number of studies have provided clues on the underlying mechanisms, which might help us to develop more targeted treatments for MS. In this Review, we discuss the evidence linking EBV to the development of MS and the mechanisms by which the virus is thought to cause the disease. Furthermore, we discuss implications for the treatment and prevention of MS, including the use of antivirals and vaccines.