A whodunit is a mystery story that keeps the criminal's identity a secret until the very end. A well-written whodunit can keep you up late turning pages, eager for the ending to be revealed.
If a book, play, or movie is a whodunit, there's usually a detective investigating what's almost always a murder case. The key to the plot, which is generally complex and confusing, is the question implicit in the informal whodunit: "Who (has) done it?" Since it was coined around 1930 in the U.S., this term has been common for a particular type of mystery or detective story.