by a nose; photo finish
Primarily a horse racing term for a very narrow margin of victory, but can be used figuratively for any extremely close contest.
His horse won by a nose.
The election was truly a photo-finish contest.
Compound of 鼻 (nose) and 差 (difference, margin), literally 'nose difference'. The term originates from horse racing, where a nose is the smallest measurable winning margin.