The inspiration for the new chamber musical Dead Outlaw is a minor Oklahoma train robber named Elmer McCurdy — the sort of footnote to history that might fuel an especially discursive episode of NPR’s This American Life. (Think Lin-Manuel Miranda’s 21 Chump Street.) But in the hands of composer David Yazbek, reteaming with his The Band’s Visit playwriting collaborator, Itamar Moses, this twisty little yarn is elevated into a bizarro-world elegy to how the American Dream can curdle into violence, cruelty, and casual indifference.

Dead Outlaw, which opened Sunday in a mesmerizing production at the Audible-backed Minetta Lane Theatre, continually subverts our expectations for a narrative focused on a Jesse James manqué who got his start in Wild West criminality late, in the first decade of the 20th century, and suffered numerous indignities that lasted well after his death in a hayloft shoot-out.

Yazbek, whose previous musicals have mostly been adaptations of movies like Dirty Rotten Scoundrels, Women on the Verge of a Nervous Breakdown, The Band’s Visit, and (most recently) Tootsie, seems liberated by the looseness and oddity of the material to produce a melodically infectious score that’s grounded in the roots-music traditions of country-folk, rockabilly and the blues — wonderfully performed by a five-piece band (led by pianist and music director Rebekah Bruce) that employs banjo and lap steel guitar to achieve its wonderful sound. (Jeb Brown, who narrates the tale, also pitches in on guitar.)

What a sound it is! The score is chock-full of catchy earworms, a rarity in modern stage musicals, from a plaintive opening lullaby (beautifully sung by Andrew Durand as young Elmer) to a big-band crooner’s torch song (delivered with cool-cat vibes by Thom Sesma) to the rollicking and jokey anthem “Dead.” The tunes, which benefit from witty and poetic turns of phrase by lyricist Erik Della Penna, are an utter treat — and you’ll be tempted to cry out for an encore just to hear them again. (Consider this lyric for an L.A. coroner recalling some of his most famous corpses: “Oh, Natalie Wood / or Natalie won’t / leave a legend / when she leaves that boat.”) Yazbek also generously spreads his gems widely among the eight-person ensemble: Julia Knitel stands out with two equally lovely, remarkably different ballads perfectly suited to characters we meet only briefly, as if in passing.

Durand, last seen chewing the corn-fed scenery in Broadway’s Shucked, is a commanding presence as the hot-tempered striver Elmer — but soon shifts into a stoic figure of dissipation when the story takes an abrupt turn at the midway point. And while Durand’s Elmer is the center of the story as the title character, this show is a true ensemble piece in an old-fashioned sense.

In the second half, Moses’s book shifts the focus from one criminal wannabe to a circus sideshow that followed his death, casting a glaring spotlight on Americans’ perpetual proclivity toward voyeurism and the macabre. The ensuing scenes occasionally seem repetitious, but this is a show that revels in the marginal notes of history — and each Ripley’s believe-it-or-not tangent is punctuated by another song that alone justifies the digression.

Director David Comer leans into the pitch-black humor of the material, making smart use of the Minetta Lane’s small stage with a moving bandstand on wheels that doubles as a train car (set design by Arnulfo Maldonado) — and some ingenious visual tableaux (including a surprise near the end) that are enhanced by Heather Gilbert’s shadowy lighting design. The overall result is a visual and aural delight, an affectionate dive into a forgotten chapter from the American past that recalls the having-fun-with-history energy of Bloody, Bloody Andrew Jackson, but in a way that’s both more grounded and less weighty. Dead Outlaw unearths the corpse of forgotten history — and you’d be foolish to avert your gaze or stopper your ears to this dark, daring and delightful new musical.