in the figurative sense of "something unlikely," 1867, from long (adj.) + shot (n.). The notion is of a shot at a target from a great distance, thus difficult to make. Cinematic sense is from 1922.
not by a long shot
: a long-shot victory