With Robert Downey Jr. making him a skull-cracking action hero on the big screen and Benedict Cumberbatch making him a high-functioning sociopath on TV, what sort of Sherlock Holmes yarn can add fresh story material? How about Ian McKellen playing the immortal character as we’ve never seen him before?

The Sherlock we meet in “Mr. Holmes” is a man of growing frailties, gently portrayed. Well into the dusk of his life at 93, his recollection has declined worryingly. The long-retired consulting detective also dislikes the fame thrust upon him by Dr. Watson, whose largely unreal stories, he said, “made me into a fiction.” He never occupied 221B Baker St. (a myth “to mislead the curious”), disdains the famous deerstalker cap and didn’t own a curved pipe (he smokes cigars).

“If I ever write a story myself,” McKellen’s true Sherlock complains, “it will be to correct millions of misconceptions created by his imaginative license.”

He lives far from London in a rustic home on the cliffs above the English Channel. He devotes his reclusive days to beekeeping, negotiating with his irascible housekeeper Mrs. Munro (Laura Linney) and entertaining her young son Roger (delightful child actor Milo Parker). Now, in 1947, he has outlived his own life story.

When the inquisitive Holmes visits a movie theater to catch a cloak-and-dagger Sherlock film, the melodrama annoys him. Sherlock (played by Nicholas Rowe, who in 1985 had the lead in “Young Sherlock Holmes”) receives a hokey portrayal that prompts a sigh from Mr. Holmes. When he leaves he does not encounter a single city street covered in fog.

Directed by Bill Condon (“Gods and Monsters,” “Kinsey” and “Dreamgirls”) from a script by Minneapolis writer Jeffrey Hatcher, “Mr. Holmes” recalls an earlier film about the downward spiral of memory loss, last year’s Oscar-winning “Still Alice.” The aging Holmes, no longer so skillful at solving puzzles, works to re-evaluate secrets within his own life and his place in the world.

The mystery most on his mind is an investigation dating back 30 years, a vexing case that moved him into retirement. Ann Kelmot (Hattie Morahan) was considered by her husband to be wandering far and wide following repeated miscarriages. Was she led away by woe, malice or illicit love?

Holmes recalls shadowing Ann, interviewing her and learning the truth, a solution that troubles him decades afterward. “I must have done something terribly wrong,” he frowns, studying his memory-lapsed diary and imagining himself back on the case.

The film takes place in three eras. In flashbacks to 1917, Holmes is open-eyed and authoritative at 60, sleek in his top hat and walking with a sure-footed gate. Directly after the conclusion of World War II, he visits bomb-ravaged Japan, where he was invited to sample a rare plant that helps rejuvenate memory loss. In late 1940s England, he is awkward intellectually and physically, moving clumsily with a cane, wearing liver-spot makeup on his skin and a prominent false nose. At 76, the actor looks almost 100.

McKellen, who gets under the skin of every character he plays, takes Sherlock in new directions. The Holmes he creates is brusquely direct, but not the icy logical thinker we’ve met often before. The detective’s gentle bond with the inquisitive young Roger is a charming mentor and protégé relationship. When it is threatened, you ache for both.

McKellen also delivers the role’s humor with a sly wink to the audience, grumbling after he tumbles out of bed and cuts himself, “I look like I’ve been attacked by the hound of the Baskervilles.” I can’t remember another time when a faltering character has been played with such complete authority.