On a historical level one can fault this retelling of the English breaking of the Nazi Enigma code, the complex system through which German military instructions were sent to the field —an episode of World War II previously dramatized, though none too successfully, in Michael Apted’s “Enigma” (2001)—for inaccuracies. (Anthony Lane has done so in his New Yorker review.)

But expecting pure factual precision of a movie about a historical figure is the height of folly, and even if one accepts Christian Caryl’s scathing assessment of the film’s veracity in The New York Review of Books as completely correct, it’s still the case that despite the instances in which it strays from, or grossly simplifies, the record, “The Imitation Game” succeeds in presenting an affecting portrait of Alan Turing, the brilliant Cambridge mathematician who was an important part of the team at Bletchley Park that deciphered the intricate workings of the captured machine that spat out directives that were differently encrypted each day.

It’s certainly true that the film, directed rather blandly by Morten Tyldum from a script that Graham Moore adapted from the Turing biography by Andrew Hodges, pretty much turns the cracking of the Enigma code into a one-man achievement, though it does make a nod in the direction of the sole woman on the team. Still, though it exaggerates the singularity of Turing’s role, that’s to be expected given the exalted status he’s come to have in recent years—not only for his part in the Enigma triumph but his role in the early development of computers, as well as for his unhappy experience as a homosexual at a time when his sexual orientation remained a crime in England.

It is, in fact, that last fact with which the film begins. After an apparent break-in and ransacking of his house in 1952, Turing (Benedict Cumberbatch) is investigated as a possible spy by a detective (Rory Kinnear) who instead discovers that the professor is gay. What follows is in effect an extended flashback, in which Turing narrates his wartime experience from 1939, when he joined the Bletchley project directed by Naval Commander Alistair Denniston (Charles Dance). The film presents him as an arrogant, eccentric, socially awkward fellow who appeals directly to Winston Churchill to put him in charge of the operation, much to the dismay of Denniston and de facto leader of the group Hugh Alexander (Matthew Goode), who along with his colleagues is exasperated by Turing’s obsession with building a device that will unravel the Enigma machine’s secrets. Turing’s only support, initially at least, comes from Joan Clarke (Keira Knightley), whom he goes to great lengths to recruit for a slot on the team, and to whom he’ll become engaged despite his homosexuality. But eventually his intensity will convince Alexander and the rest of the team to rally to his side when he’s threatened with dismissal, and ultimately a chance remark in a pub, of all places, will give him the idea that allows his computing machine to break the code and help win the war.

All of this is laid out by Moore in a fundamentally formulaic fashion that contains a substantial amount of revisionism and no little invention (a subplot about a team member who’s a Russian spy and uses his knowledge of Turing’s sexual preferences to blackmail him to be silent about it seems to have been made up out of whole cloth). But as a film it works precisely because it follows expectations about troubled geniuses who triumph in the face of powerful opposition. And it happens to be grounded in a superb performance by Cumberbatch, who inhabits this vision of Turing so completely that one is willing to accept it. Knightley brings welcome vivacity to Clarke, and Goode makes a handsome foil to, and later comrade of, Turing, while Dance has an obviously fine time playing a snooty disciplinarian not at all amused by his hireling’s oddities—though the real Denniston seems to have been a totally different sort of person. And one shouldn’t overlook the remarkable work by Alex Lawther, who plays the young Turing, an outcast befriended by Christopher Morcom (Jack Bannon), a supportive classmate who becomes his first love, to whose loss Turing can never reconcile himself.

It is, in any event, at the very point when the code is broken that “The Imitation Game” moves into more psychologically complex and ethically ambiguous territory, as Turing and his colleagues—including Churchill and a smooth M.I.6 operative (Mark Strong)—must decide what decrypted information to act on and what to let pass unnoticed in order to keep the Germans from recognizing that their messages are now being read by the enemy. It leads Turing into the same sort of quandary over the way in which his work is used that Robert Oppenheimer experienced after the success of the Manhattan Project in the United States. Of course, in line with the structures of formula screenwriting, Moore ties that with Turing’s increasingly self-destructive tendencies, which lead to his physical deterioration under the effect of drugs mandated to deal with his homosexual tendencies and his death in 1954, perhaps by his own hand.

In short, the story of Alan Turing has been transformed by Moore and Tyldum into a biographical arc that in many respects has less to do with the actual man than with a formulaic view of what such a man ought to have been. One can criticize that as historically dishonest, but the fact remains that it’s dramatically satisfying, especially when served up as well as Cumberbatch, Knightley, and their colleagues do. The physical side of the film is as accomplished as the performances, with the production design (Maria Djurkovic), art direction (Nick Dent, Rebecca Milton and Marco Restivo), and costumes (Sammy Sheldon) offering a rich sense of period detail and Oscar Faura’s widescreen cinematography capturing it all it vibrant images. Alexandre Desplat, as usual, contributes a score that adds considerably to the visuals by doing the unexpected.

Caryl calls the result a bad imitation of Alan Turing, and by historical standards it is. If you want an accurate treatment of his life, read Hodges. But so long as you understand that what it’s imitating is not so much Turing’s life as successful examples of what Hollywood calls biopics, embracing a certain set pattern about tormented genius, it’s quite a good “Imitation.”