Like NVZ said, I usually move on from the subject as well.
Some people get hints easier than others, at the start I would simply not give back any positive feedback to their story if it's of the 'one up' nature.
A polite way of doing this is changing the topic once they are done to something completely different - Not another story because it might still seem to them like you're in the 1-up battle by bringing a better story to the table, but more like just general conversation.
A less polite way to handle it would be to walk away once they are done with their story, giving no positive feedback. Eventually, they'll realize that not only are they not getting the ego boost they are looking for but that they're alienating you in the process.
A more direct approach, I have had one good friend with whom I took this approach, was to be direct, say something along the lines of
Sometimes I get the feeling that you're not listening to me when I talk, quite often I want to share a personal story with you and end up feeling as if you're only waiting for me to finish to tell your own story on the subject.
I'm sure the intentions are not to 'one up' you, so by changing their position from a less talkative to a more attentive one might keep them on topic.
As a last resort, which I've also taken many times, simply disregard that friend as such a close friend, accept them for who they are and understand that sometimes it's not your job to change them.
Also be wary of your surroundings, sometimes (often?) the 'one uppers' will be more of the 'one up' nature when in a crowd but behave completely different in a 1:1 conversation.