win (something) by a hair
To succeed or defeat someone in something by only a very narrow margin. Making huge gains during the final lap, the underdog rookie managed to overtake the reigning champion and win the race by a hair. We only won by a hair, but at least we got the conviction we were looking for.