A diffident young man with extraordinary gifts enters a hallowed school, encounters smooth-talking devils and deadly skullduggery, and leads a revolutionary upheaval. The thematic links between Daniel Radcliffe’s iconic role as a lightning-scarred boy wizard and his new performance as college-bound Allen Ginsberg are plentiful. This time he’s out not to defeat Lord Voldemort but to unseat America’s best-known poet of the 1940s, that purveyor of genial tripe Ogden Nash, and all the stale mediocrity that he represents. The path leads through sex, drugs, poetry and lethal violence.

“Kill Your Darlings” is a true-crime murder mystery, a love letter to the wild-living artists of the Beat Generation, and a portrait of the artist as an adolescent. The setting is New York City’s Columbia University, re-created with flawless World War II period detail. Ginsberg, the son of a notable poet, possesses a prodigious imagination struggling to burst free. Radcliffe rings true on every note, capturing the insecurity of a kid from small-town New Jersey and the mad exhilaration of a writer possessed by angelic voices. You can believe he’s the offspring of a demanding dad (David Cross) and a nutso mom (Jennifer Jason Leigh) who hears the electrical wires in the walls talking to her.

Gradually shrugging off his inhibitions, Ginsberg enters a coven of young iconoclasts bent on creating a modern American literature that flouts all the rules of conventional form and decency. Upper-class dilettante Lucien Carr (Dane DeHaan), a blue-eyed boy-magnet, recognizes the nervous, talented freshman as a potential lover and promising ghost writer for his college papers. The naïve, socially awkward Ginsberg sees in Carr’s seductive wit and bravado all the confidence he wishes that he possessed.

Through Carr, Ginsberg meets the somewhat older hipsters William Burroughs (Ben Foster), introduced huffing nitrous oxide in a Greenwich Village bathtub, and Jack Kerouac (Jack Huston), a dashing onetime Columbia football star. As Carr’s new beau and scribe, Ginsberg would replace David Kammerer (“Dexter’s” Michael C. Hall), a professor who followed Carr from school to school, professing his undying devotion. When Kammerer turns up in the Hudson River with stab wounds, the ensuing scandal and investigation entangle Ginsberg, Burroughs and Kerouac, still years from recognition.

The casting is wonderful. DeHaan is condescending, sensitive, pretend-brilliant and deeply insecure as the Salieri to Radcliffe’s Mozart. Ben Foster is the martini-dry Burroughs incarnate, from the scratchy, atonal speaking voice to the air of genteel depravity that the wealthy drug connoisseur radiated. Huston has the young Kerouac’s gridiron-star charisma, and Elizabeth Olsen is tart in her fleeting appearance as his neglected, put-upon fiancée.

This is not their story, however. The focus is on Ginsberg, with Radcliffe maturing fast from a naive newcomer to the moral compass of his bohemian clique. He drifts through hopped-up jazz club reveries with a look of dazed awe, and tackles his first amphetamine-fueled writing binges with the cockeyed delirium of an artist burning to express the nature of the universe. When the drugs are put away, though, he’s more morally centered than the others. The crux of the film is his quandary: Should he tell the district attorney what he knows about Kammerer’s death or betray his principles to save a friend?

First-time writer/director John Krokidas didn’t craft an elegant screenplay, but he tells an engaging story while avoiding obvious pitfalls. “Kill Your Darlings” (the title comes from a piece of stock advice for beginning writers) could have been a predictable gay awakening tale or the clichéd story of a writer discovering his voice. Instead, it’s a rich look at the formative days and growing pains of a game-changing artistic movement and an individual’s conscience.