The origins of this idiom.
The meaning of this phrase.
(1) A horse racing term that refers to two or more horses who are side by side, evenly matched. (2) Competitions or comparisons that are very close, e.g., when comparing the gas mileage between two cars, if both cars have equal gas mileage, then they can be said to be 'neck and neck.'
There are several phrases that originate from horse racing, and by the looks of it, this saying is yet another one that does so as well.

This saying goes back to at least the early to mid-19th century where it was a common term used in horse races. Oftentimes, during a race, horses and their riders will be evenly matched, running side by side with each other. When this happens, the horses are said to be neck and neck. Today,this phrase is used, not just in reference to horses that are evenly matched, but also to other types of competitions where things are close.

The earliest example of this phrase that I could find in writing comes from the Tasmanian and Port Dalrymple Advertiser newspaper, 1825, where it is indeed being used in the context of a horse race:

    "The owners rode their respective horses, and the race was said to be the finest ever witnessed on this turf, 
     both horses keeping neck and neck round the course."


Know Your Phrase - The Meanings and Origins For Phrases and Common Idioms > N-Letter Sayings
Title image for the phrase Neck and Neck.
Image for - Phrases and Sayings starting with the letter N.
* Nick and Thomas wanted to see who could do 30 push ups in the fastest time, and when they started, they were neck and neck all the way to the very end.

* These oatmeal and chocolate chip cookies Deb made this morning taste great! In terms of flavor, I'd say they are both neck and neck.

Phrases and Idioms
Bottom note box.
knowyourphrase.com - The Meanings and History For Popular Idioms and Phrases | Use this handy list of phrases to search for more! 
Note: The origins for most common idioms cannot be said with a certainty. What's provided are theories that may be plausible to how a phrase originated, but not necessarily so. 

In addition, quotes that contain a phrase may be taken from old newspapers, poems, or books that were written centuries ago, but this by no means shows they originated from these. In all likelihood, if an expression is being used in a newspaper, it's probably already well known, and thus, from an older period of time.