For the first eighty minutes or so, David Koepp’s filmization of Stephen King’s novella “Secret Window, Secret Garden” is a satisfyingly unnerving bit of American Gothic, beautifully produced, cannily directed, and anchored by bravura performances from Johnny Depp and John Turturro, both of whom tear into their roles with a malicious glee that brings out all the script’s mordant humor. Unfortunately, in the final twenty, when the big plot revelation occurs and Gothic turns into Grand-Guignol, the picture becomes a veritable self-parody, with so many Kingisms tumbling over one another–mostly twists and devices that are thinly altered reminiscences of “The Shining” (not to be revealed here)–that “Secret Window” winds up seeming rather like variations on a very familiar theme.

The plot is actually very simple. With a nod to “Misery,” the lead character is a King-like author named Mort Rainey (Depp), who’s in terrible shape. Bedraggled and unkempt, he’s living at an isolated lakehouse in upstate New York. He’s separated from his wife Amy (Maria Bello), whom he’d caught in a distinctly compromising position with Ted Milner (Timothy Hutton); their divorce is pending, though–as it’s later revealed–Mort has been reluctant to sign the final papers. Clearly demoralized by this turn of events in his family life, Mort is also suffering from a terrible case of writer’s block, especially since he’s been trying to come to terms, in the literary sense, with Amy’s infidelity. As if all this wasn’t bad enough, Rainey’s isolation is shattered by the arrival of a terrifying stranger–one John Shooter (Turturro), a menacing Mississippian wearing a black hat, who accuses the author of stealing a story he’d actually written. Shooter’s threats against Mort quickly escalate, and when the local sheriff (Len Cariou) proves of no help, Rainey turns to Ken Karsch (Charles S. Dutton), a tough-as-nails New York PI who had helped him before–in an earlier case of plagiarism, as it happens. Eventually Shooter aims his threats not only against Mort but against Amy as well, and both Rainey and Karsch come to suspect that Ted might have something to do with the man’s abrupt appearance. It wouldn’t be fair to reveal the turns that the plot takes from here. Suffice it to say that astute viewers–maybe even more cursory ones–may be inclined to detect debts not only to “The Shining” but also to Anthony Shaffer’s “Sleuth,” in terms of both tricky identifications (though the rationale behind them is quite different here) and the elaborate interior production design by Howard Cummings–in many respects Rainey’s mazelike house is as intricate, though hardly as elegant, as writer Andrew Wyke’s (Laurence Olivier) abode–designed by Ken Adam–was in Joseph Mankiewicz’s 1972 version of that play.

What keeps “Secret Window” humming even over the rough spots, however, are the performances and the extraordinarily effective degree of control by writer-director David Koepp. Depp offers another of the outrageous, risk-taking turns that have served him so well in the past, most recently in “Pirates of the Caribbean.” He’s enormously enjoyable to watch–it’s impossible to predict what weirdness he’s going to resort to next–and certainly there’s no other leading man who would have dared to wear the hairdo (or lack thereof) he sports throughout. Turturro matches him with a gloriously over-the-top reading that turns Shooter into a figure almost as frightening as Robert Mitchum’s Preacher in Charles Laughton’s 1955 masterpiece “The Night of the Hunter” (although he doesn’t get the opportunity to affect that character’s suave, falsely pleasant side). Bello and Hutton haven’t anywhere near the same opportunities, but they make the most of what’s given them, and Dutton repeats his gruff routine competently. But even the best actors couldn’t have carried the film without Koepp’s expert contribution. His adaptation of King’s prose is clever and his structuring of the story cunning, and his direction exhibits the same ability to generate tension and fear as he demonstrated in his hugely undervalued 1999 adaptation of Richard Matheson’s “Stir of Echoes.” Fred Murphy’s cinematography and Jill Savitt’s editing are also worthy of praise, but special mention is due to Philip Glass’ exceptional score–one that recalls, with its moody, repetitive themes, the style of the incomparable Bernard Herrmann. Even in the last reel, when the script goes as berserk as one of the major characters, the music never disappoints.

“Secret Window” is easily the best King adaptation in years–though that’s not really saying much. The picture is, to be sure, dumb fun, a piece of pulpish nonsense lavishly done up in A-list style from beginning to end and milking its vein of black humor to the full. After it’s over, you may feel that the accent is on the “dumb,” and that the “fun” is definitely lessened by the highly derivative nature of those final twenty minutes. Still, for all its last-act problems, the picture’s stylishness, genuinely unsettling atmosphere and spectacular lead performances make it an enjoyably creepy thrill-ride.