pip at the post

pip at (to) the post (to beat in a competition or race by a very small amount; to defeat someone whose success seems certain) {Brit & NZ slang} — обойти у самого финиша; победить на "флажке"; победить с минимальным перевесом; вырвать победу в последнюю минуту

Example 1: Edge Hill University was pipped at the post last night by the University of Exeter in the race for the coveted Times Higher Educational Supplement University of the Year Award for 2007. (edgehill.ac.uk)

Example 2: The maverick 46-year-old Conservative backbencher pipped fellow Tory Sir George Young to the post to clinch the £146,041-a-year post, which comes with a grace-and-favour palace in the heart of Westminster. (guardian.co.uk)