Inactivation is the process by which ion channels terminate ion flux through their pores while the opening stimulus is still present1. In neurons, inactivation of both sodium and potassium channels is crucial for the generation of action potentials and regulation of firing frequency1,2. A cytoplasmic domain of either the channel or an accessory subunit is thought to plug the open pore to inactivate the channel via a 'ball-and-chain' mechanism3-7. Here we use cryo-electron microscopy to identify the molecular gating mechanism in calcium-activated potassium channels by obtaining structures of the MthK channel from Methanobacterium thermoautotrophicum-a purely calcium-gated and inactivating channel-in a lipid environment. In the absence of Ca2+, we obtained a single structure in a closed state, which was shown by atomistic simulations to be highly flexible in lipid bilayers at ambient temperature, with large rocking motions of the gating ring and bending of pore-lining helices. In Ca2+-bound conditions, we obtained several structures, including multiple open-inactivated conformations, further indication of a highly dynamic protein. These different channel conformations are distinguished by rocking of the gating rings with respect to the transmembrane region, indicating symmetry breakage across the channel. Furthermore, in all conformations displaying open channel pores, the N terminus of one subunit of the channel tetramer sticks into the pore and plugs it, with free energy simulations showing that this is a strong interaction. Deletion of this N terminus leads to functionally non-inactivating channels and structures of open states without a pore plug, indicating that this previously unresolved N-terminal peptide is responsible for a ball-and-chain inactivation mechanism.