IMPORTANCE The risk of epilepsy after neonatal invasive Group B Streptococcus (iGBS) disease, particularly iGBS sepsis, is poorly understood. OBJECTIVE To examine the association between neonatal iGBS (sepsis or meningitis) and long-term risk of epilepsy, stratified by sex, prematurity, and maternal socioeconomic position (SEP). DESIGN, SETTING, AND PARTICIPANTS This population-based cohort study was conducted in Denmark with an inclusion period from 1997 through 2017 and follow-up until the end of 2018. A general population comparison cohort was randomly sampled and matched up to 10:1 to the exposed cohort. Linkage between Danish national registers were applied for data collection. Participants were infants aged 0 to 89 days. The general population comparison cohort was matched by sex, the child's year and month of birth, and gestational age. SEP was defined by maternal income and education. EXPOSURE Hospital-diagnosed iGBS (sepsis or meningitis) during the first 89 days after birth. OUTCOMES AND MEASURES Epilepsy was defined by International Statistical Classification of Diseases and Related Health Problems, Tenth Revision codes and/or prescription codes for antiepileptic drugs using Danish medical registry data. Cumulative risk (CR) of epilepsy was calculated by treating death as a competing event. Cox proportional hazards regression was used to estimate hazard ratios with 95% CIs. Effect modification by sex, prematurity, and maternal SEP was assessed on an additive scale. RESULTS A total of 1432 children (792 [55.3%] boys; 1126 [78.6%] with gestational age >= 37 weeks) were identified with iGBS disease: 1264 with sepsis and 168 with meningitis. In the comparison cohort, there were 14211 children (7869 [55.4%] boys; 11260 [79.2%] with gestational age >= 37 weeks). The overall (0 to 22 years) CR of epilepsy was 3.6% (95% CI, 2.6%-5.0%) in children with iGBS disease and 2.3% (95% CI, 1.9%-2.7%) in the comparison cohort. The overall CR of epilepsy for iGBS meningitis was 15.1% (95% CI, 8.9%-22.8%) and 2.2% (95% CI, 1.4%-3.4%) for iGBS sepsis. The adjusted hazard ratio for epilepsy in children with iGBS disease was 2.04 (95% CI, 1.46-2.85). Being a boy, born premature, or born to a mother belonging to a low SEP group was associated with an increased risk of epilepsy in later childhood. CONCLUSION In this population-based cohort study of 1432 neonates, iGBS disease was associated with a higher incidence of epilepsy in later childhood, notably after meningitis. Premature birth, sex, and low maternal SEP modified the association.