late 14c., "narrative with a happy ending; any composition intended for amusement," from Old French comedie (14c.), "a poem" (not in the theatrical sense) and directly from Latin comoedia, from Greek kōmōidia "a comedy, amusing spectacle," probably [Beekes] from kōmōidos "actor or singer in the revels," from kōmos "revel, carousal, merry-making, festival" + aoidos "singer, poet," from aeidein "to sing," which is related to ōidē (see ode).
The passage on the nature of comedy in the Poetic of Aristotle is unfortunately lost, but if we can trust stray hints on the subject, his definition of comedy (which applied mainly to Menander) ran parallel to that of tragedy, and described the art as a purification of certain affections of our nature, not by terror and pity, but by laughter and ridicule. [Rev. J.P. Mahaffy, "A History of Classical Greek Literature," London, 1895]
The origin of Greek komos is uncertain; perhaps it is from a PIE *komso- "praise," and cognate with Sanskrit samsa "praise, judgment." Beekes suggests Pre-Greek. The old derivation from kome "village" is not now regarded.
The classical sense of the word was "amusing play or performance with a happy ending," which is similar to the modern one, but in the Middle Ages the word meant poems and stories generally (albeit ones with happy endings), such as Dante's "Commedia." The revival of learning 16c. recovered the ancient comedies and shifted the sense of the word to "branch of drama addressing primarily the humorous and ridiculous" (opposed to tragedy). In 18c. this was somewhat restricted to "humorous, but not grossly comical, drama" (opposed to farce).
Comedy aims at entertaining by the fidelity with which it presents life as we know it, farce at raising laughter by the outrageous absurdity of the situation or characters exhibited, & burlesque at tickling the fancy of the audience by caricaturing plays or actors with whose style it is familiar. [Fowler]
Meaning "comic play or drama" is from 1550s (the first modern comedy in English was said to be Nicholas Udall's "Roister Doister"). Extended sense "humorous or comic incident or events in life" is from 1560s. Generalized sense of "quality of being amusing" dates from 1877.