Hey, I still want to know what that means

If somebody is leading the race for the whole duration but then somebody sprints up and beats them at the very end?
They have been pipped at the post.
It is a very quaint,old English saying that has its origins in horse racing i believe!