It means to be very near and almost accomplish a goal, but fall short. It also means to fall short of a successful outcome and get nothing for your inputs in either way.
It is word of US origin and is generally used in contexts where one loses anything in a nick.
1) "Close, young man, but no cigar!", exclaimed the coach to his student.
2)"Oh..!! the match was close, but no cigar", sighed the captain of the team.
3)Some incidents in the history were titled Close, but no cigar.