1855, theater slang for "a failure in performance;" by 1862 it had acquired the general sense of "any ignominious failure or dismal flop," on or off the stage. It comes via the French phrase fiare fiasco "turn out a failure" (19c.), from Italian far fiasco "suffer a complete breakdown in performance," literally "make a bottle," from fiasco "bottle," from Late Latin flasco "bottle" (see flask).
The literal sense of the image (if it is one) is obscure today, but "the usual range of fanciful theories has been advanced" [Ayto]. Century Dictionary says "perhaps in allusion to the bursting of a bottle," Weekley pronounces it impenetrable and compares French ramasser un pelle "to come a cropper (in bicycling), literally to pick up a shovel." OED keeps its distance and lets nameless "Italian etymologists" make nebulous reference to "alleged incidents in Italian theatrical history." Klein suggests Venetian glass-crafters tossing aside imperfect pieces to be made later into common flasks. But according to an Italian dictionary, fare il fiasco used to mean "to play a game so that the one that loses will pay the fiasco," in other words, he will buy the next bottle (of wine). If the dates are not objectionable, that plausibly connects the literal sense of the word with the notion of "a costly mistake."