Temporal lobe epilepsy is the most common type of epilepsy in adults, is often medically refractory, and due to broad actions and long-time scales, current systemic treatments have major negative side-effects. However, temporal lobe seizures tend to arise from discrete regions before overt clinical behaviour, making temporally and spatially specific treatment theoretically possible. Here we report the arrest of spontaneous seizures using a real-time, closed-loop, response system and in vivo optogenetics in a mouse model of temporal lobe epilepsy. Either optogenetic inhibition of excitatory principal cells, or activation of a subpopulation of GABAergic cells representing <5% of hippocampal neurons, stops seizures rapidly upon light application. These results demonstrate that spontaneous temporal lobe seizures can be detected and terminated by modulating specific cell populations in a spatially restricted manner. A clinical approach built on these principles may overcome many of the side-effects of currently available treatment options.