This phrase, together with win by a neck below, originally developed with reference to horse racing. A neck is the length of the head and neck of a horse as a measure of its lead in a race. More @Wikipedia
Hover over any link to get a description of the article. Please note that search keywords are sometimes hidden within the full article and don't appear in the description or title.