When he was an immigrant boy growing up in New Jersey, the writer Junot Díaz said he felt marginalized. But that feeling was dispelled somewhat in 1981 when he was in sixth grade. He and his buddies, adventuring pals with roots in distant realms — Egypt, Ireland, Cuba and the Dominican Republic — became “totally sucked in,” he said, by a “completely radical concept: role-playing,” in the form of Dungeons & Dragons.

Playing D&D and spinning tales of heroic quests, “we welfare kids could travel,” Mr. Díaz, 45, said in an email interview, “have adventures, succeed, be powerful, triumph, fail and be in ways that would have been impossible in the larger real world.”

“For nerds like us, D&D hit like an extra horizon,” he added. The game functioned as “a sort of storytelling apprenticeship.”

Now the much-played and much-mocked Dungeons & Dragons, the first commercially available role-playing game, has turned 40. In D&D players gather around a table, not a video screen. Together they use low-tech tools like hand-drawn maps and miniature figurines to tell stories of brave and cunning protagonists such as elfish wizards and dwarfish warriors who explore dungeons and battle orcs, trolls and mind flayers. Sacks of dice and vast rule books determine the outcome of the game’s ongoing, free-form story.