The site states that the saying came from the custom of early slot machines awarding cigars to winners. A third theory comes from Take Our Word for It, which says nobody knows exactly how the phrase came about, but that it likely came to prominence at carnivals, specifically the game where players use a sledgehammer to ring a bell. Macho victors were given cigars, while the wimps were told they came close, but they would not be receiving any carcinogenic tobacco for their efforts.
(The above was pasted from another site)