This means to fall short of a successful outcome. It was first used in the United States in the early 1900s and is likely the phrase originated at fairgrounds.
Much like fairs today, booths would be set up and fair workers would
host difficult to win games for fair goers to try. Games of
strength, accuracy, and skill were played by men and women. Back
then, prizes were for mom and dad, and cigars were a very common
prize given out to winners. The phrase apparently originated when
someone came close to winning one of the games, but ultimately lost
and so did not win a cigar. Workers yelled it out out when people
lost, trying to draw crowds and encourage the person to try again.
As the fairs traveled, the phrase spread rapidly and it began to be
used any time someone did not meet expectations.