The story
From the practice of giving cigars as prizes at carnivals in the United States in the 20th century; those who did not win would fail to receive a cigar, even if they came close.
First known use, by meaning
- from early 20th c. Used to indicate that one is almost correct or has almost succeeded, but not quite.
Etymology from Wiktionary, CC BY-SA 4.0.