By a whisker

Just barely, by a very small amount.

The marathon runner won the race by a whisker.