The film is narrated by a small-time criminal, Harry Lockhart (Robert Downey Jr.). He is self-aware and talks to the audience at various times throughout the movie. (See also the theatre concept of the fourth wall and metafiction.)
Running from police after a botched robbery, Harry evades the cops by running into a movie audition for a hardboiled film and, ironically, impresses the producers with his recollection of the late 'hit' having gone awry and resulting in the death of his accomplice (which they mistake for rehearsing material). He is then brought to Hollywood, where he's introduced to homosexual private investigator "Gay" Perry van Shrike (Val Kilmer), enlisted to help Harry prepare for his role in the movie.
Harry is introduced to Hollywood parties and encounters his dream-girl, Harmony Lane (Michelle Monaghan), a girl Harry has known since childhood. The two childhood friends leave for Harry's apartment, but budding romance is squelched when Harry proceeds to drunkenly have sex with Harmony's friend.
Following around Perry at his job, Harry stumbles upon evidence of a complicated murder mystery eerily similar to the detective stories that Harry and Harmony grew up reading. The three team up to solve the mystery and encounter a series of seemingly nonsensical problems.