In bacterial voltage-gated sodium channels, the passage of ions through the pore is controlled by a selectivity filter (SF) composed of four glutamate residues. The mechanism of selectivity has been the subject of intense research, with suggested mechanisms based on steric effects, and ion-triggered conformational change. Here, we propose an alternative mechanism based on ion-triggered shifts in pKa values of SF glutamates. We study the NavMs channel for which the open channel structure is available. Our free-energy calculations based on molecular dynamics simulations suggest that pKa values of the four glutamates are higher in solution of K+ ions than in solution of Na+ ions. Higher pKa in the presence of K+ stems primarily from the higher population of dunked conformations of the protonated Glu sidechain, which exhibit a higher pKa shift. Since pKa values are close to the physiological pH, this results in predominant population of the fully deprotonated state of glutamates in Na+ solution, while protonated states are predominantly populated in K+ solution. Through molecular dynamics simulations we calculate that the deprotonated state is the most conductive, the singly protonated state is less conductive, and the doubly protonated state has significantly reduced conductance. Thus, we propose that a significant component of selectivity is achieved through ion-triggered shifts in the protonation state, which favors more conductive states for Na+ ions and less conductive states for K+ ions. This mechanism also suggests a strong pH dependence of selectivity, which has been experimentally observed in structurally similar NaChBac channels.