Borrowing a page from “Sunset Boulevard,” this dreamy black comedy is narrated by a corpse: Lester Burnham (Kevin Spacey), a going-nowhere writer for Media Monthly who already considers himself among the walking dead. His Realtor wife (Annette Bening) is chilly and compulsive, his daughter (Thora Birch) loathes him and his boss is about to fire him. What brings him back to life is a glimpse of his daughter’s high-school classmate Angela (Mena Suvari), seductively strutting her cheerleader’s stuff on a basketball court. Emboldened by mad desire, he quits his job, starts pumping iron, smoking pot and generally behaving like a man “with nothing to lose.” Lester is in a state of reckless, deluded grace, and Spacey, whose comic timing is as dry as a perfect martini, manages to make him both snakily dangerous and strangely endearing.

“American Beauty” is a very funny film that packs an unexpected emotional wallop. It seems to condescend to its characters, but just when you think it will turn sour, these cardboard cutouts turn flesh and blood. Bening, a wonderful comedian, zigzags dazzlingly between parody and pathos. The film’s most mysterious character is the strange, pot-selling teenager, Ricky Fitts (Wes Bentley; following story), who falls for Lester’s daughter. He’s the son of a homophobic ex Marine colonel (Chris Cooper) who’s just moved next door. It’s typical of the movie’s sleight of hand that the eeriest character just might be the film’s moral center.

Mendes, who directed the acclaimed stage revival of “Cabaret,” uses the screen like a born filmmaker. He and cinematographer Conrad Hall create bold, spare images suspended somewhere between Caravaggio and comic strip. His film examines a malaise that’s been plaguing the affluent, deracinated middle class since the suburbs were invented. It’s about the power of the images we have in our heads, and the painful gulf between those fantasies and the reality we can’t seem to grasp. The beauty of “American Beauty” is how wickedly entertaining it makes this bleak diagnosis.