The origin is indeed in sport, though not football but horse-racing. American racetracks in the latter part of the nineteenth century — before the days of cameras — had a wire strung across the track above the finishing line to help stewards decide which nose had got across the line first. An early example appeared in Scribner’s Magazine in July 1889: “As the end of the stand was reached Timarch worked up to Petrel, and the two raced down to the ‘wire,’ cheered on by the applause of the spectators. They ended the first half mile of the race head and head, passing lapped together under the wire, and beginning in earnest the mile which was yet to be traversed”. So, a race that was undecided until the very last moment was said to go down to the wire.
Another wire was often placed across the track at the starting post to help check for false starts; this led to another expression: from wire to wire, from the starting post to the finishing line, hence from end to end of a contest. When you are under the wire, you’re at the finishing line, figuratively at the last possible opportunity or just in time.
Steve