Ian McKellen in Mr. Holmes.

Ian McKellen is shockingly good as the infamous Sherlock Holmes in Mr. Holmes, a decidedly unorthodox twist on the sleuth’s story.

McKellen plays him as an aging man in his 90s, fighting memory loss and struggling to recall the details of a case that caused him to walk away from the detective life. He does this on an estate accompanied by his housekeeper (a typically wonderful Laura Linney), her son (the charming Milo Parker) and his bees.

The film features flashbacks to the events of 20 years before (which has McKellen playing in the vicinity of his actual age), with Holmes trying to remember the circumstances involving a beautiful woman, her husband and a Japanese man. Things are a little slow-going at first, but when the pieces all get put together, it’s a nice payoff.

Director Bill Condon is miles away from his pitiful two-film stint on the Twilight series. Here, he has made a film full of sumptuous visuals, splendid acting and good humor.

McKellen plays Holmes as a dignified, if sometimes nasty, older man who never wore that silly hat or smoked that huge pipe. In an interesting twist, his character is actually world-famous—and the subject of movies he considers garbage.

The year has been a little light on great performances so far. McKellen’s Holmes is certainly one of them. His interactions with Linney and Parker are classically good.

Condon and McKellen worked together before (Gods and Monsters). This stands as a much-welcomed reunion.

Mr. Holmes opens Friday, July 17, at the Regal Rancho Mirage Stadium 16 (72777 Dinah Shore Drive, Rancho Mirage; 844-462-7342), the Camelot Theatres (2300 E. Baristo Road, Palm Springs; 760-325-6565) and the Century Theatres at the River (71800 Highway 111, Rancho Mirage; 760-836-1940).