Sodium-Potassium Pump
Your confusion is caused by the assumption that Na+ always leaves the cell and K+ always enters. The Na+/K+ pump is there to maintain membrane potential and relative Na+ and K+ ion concentrations stable inside. When an action potential (AP) is generated, sodium channels open and sodium rushes inside to depolarize the cell( 1st phase of AP). Next, the sodium channels close and K+ begins to leave the cell (since the inside of the cell contains too many positive charges and the cell would remain depolarized if nothing was changed). Potassium leaves through leak channels. So in summary, Na+/K+ pump and the channels that are part of AP generation result in different movement of Na+ and K+ across the cell membrane. 

Here is a nice review of Na+/K+ pump and action potential generation. 
https://www.khanacademy.org/science/biology/human-biology/neuron-nervous-system/v/sodium-potassium-pump