The potassium ion channel, KcsA, gates the passage of ions through cell membranes in response to a change in pH. Recent experimental results have demonstrated the existence of two gates in KcsA: an intracellular gate and a gate at the selectivity filter. Lowering the pH opens the intracellular gate allowing ions to pass. After a period of time, however, the channel inactivates by constricting the selectivity filter and impeding the flow of ions even though the bottom gate remains open. We have used path-based molecular dynamics simulations to probe the detailed mechanism of this phenomenon by finding dynamical pathways to inactivation in KcsA. We have computed free energies and rates of inactivation that agree with recent experimental results. We also provide a molecular rationalization for the coupling between the opening and closing of the lower gate and the inactivation of the selectivity filter.