A connection between diabetes and an increased risk of epilepsy has been suggested by observational studies. Animal studies have also shown that antihyperglycemic drugs can improve seizures. However, it is unclear whether antihyperglycemic drugs have a causal role in epilepsy in humans. To investigate this potential causal relationship, a Mendelian randomisation study was conducted using International League Against Epilepsy data as the discovery set and FinnGen data as the replication set. It was discovered that three antidiabetic drug target genes, ETFDH, CYP21A2 and CYP2D6, were involved in the occurrence of epilepsy. In particular, ETFDH was identified as a target gene in both the discovery set (inverse variance weighting [IVW], odds ratio [OR] = 1.018, 95% confidence interval [CI], 1.004–1.033, p = 0.009) and replication set (IVW, OR = 1.074, 95% CI, 1.034–1.114, p = 0.00016), and CYP21A2 was identified in the discovery set (IVW, OR = 1.029, 95% CI, 1.005–1.053, p = 0.016) and replication set (IVW, OR = 1.057, 95% CI, 1.001–1.116, p = 0.045) as having a causal association with an increased risk of epilepsy. Conversely, the CYP2D6 gene was found to be a protective factor for epilepsy in both the discovery set (IVW, OR = 0.0984, 95% CI, 0.969–0.998, p = 0.025) and replication set (IVW, OR = 0.977, 95% CI, 0.955–1.000, p = 0.046). A search of DrugBank revealed that metformin, an anti-glucose drug, is an inhibitor of the ETFDH gene and may have a potential therapeutic effect on epilepsy.