For such a fat book — 528 dense pages — the 12th Bernie Gunther mystery is as brisk and agile as its German police detective protagonist. It moves back and forth between Nazi Germany in 1939 and the French Riviera in 1956, with two suspenseful tales that for a while seem unconnected but aren’t. Gunther is one of crime fiction’s most gratifyingly melancholy creations, and in “Prussian Blue” we watch him match wits with the officialdom of two Germanys, pre- and postwar. In both cases, there is plenty for Gunther to be melancholy about.

"Prussian Blue," by Philip Kerr (Marian Wood Books/Putnam)

All detective fiction takes place in a political context — Chandler’s rotten-cop-dominated L.A., even Agatha Christie’s cozy villages where class often impedes justice — but there’s nothing quite so complex, and so fraught, as a cop with a conscience trying to do what’s right while working under the Nazis. It’s not that Berlin’s most accomplished police sleuth is guiltless. He makes moral compromises in order to survive. But as a nonparty member and known social democrat, what Gunther mainly does to stay out of prison is make himself indispensable.

His necessity is what leads Nazi henchman Reinhard Heydrich to assign Gunther to clean up a messy situation at Hitler’s vacation home in Bavaria. The leader is set to show up in a week to celebrate his 50th birthday, but meanwhile an official has been shot dead by a sniper on the terrace of Hitler’s Alpine house. The tetchy fuhrer won’t like that. Heads could roll — literally. A favored execution method of the local Nazi constabulary is decapitation using a dull blade.

In all the Gunther novels, Kerr uses real personages as characters — in last year’s “The Other Side of Silence ” the novelist W. Somerset Maugham was a central figure — and in this one it’s a Nazi rogues’ gallery of Nuremberg candidates. (The time is April 1939, and the invasion of Poland is five months away.) Hitler’s deputy Martin Bormann is Gunther’s chief goad. And then becomes an impediment, as Gunther discovers that nearly everybody in the neighborhood hates the Nazis. Hundreds had motives to kill Karl Flex, an engineer involved in the construction of a complex that’s essentially becoming the capital of the new Germany. (In Berlin, Kerr writes, Hitler got only 31 percent of the vote and he doesn’t trust this city of cosmopolites. ) In the event that Gunther fails to find the real killer, the ever-efficient Bormann has an innocent man in the lockup who will have to take the rap. Saving this unlucky fellow is part of what spurs Gunther on.

The Nazis are basically a corrupt criminal gang, making Gunther’s job tricky. Local people who refuse to sell their houses to officials arrive home to find their roofs missing. It’s possible to buy one’s way out of the draft and into a “reserved occupation.” All the party bosses are getting a cut of the profits from construction work, drug dealing and the local brothel. Gunther uncovers a new problem with the drug trade, a shortage; methamphetamines are being diverted from civilian to military use as part of the run-up to war.

Gunther’s assistant in his investigation, a wily young man named Frederich Korsch, turns up 17 years later as an official of the East German Stasi. His old buddy is now tracking Gunther in order to kill him for refusing to leave his postwar job as a hotel concierge in Nice and assassinate Gunther’s estranged wife, Elisabeth. To show how serious the Stasi is, Gunther is nearly hanged by Korsch and a couple of other thugs.

The author Philip Kerr. (Nina Subin)

In Kerr’s deft hands, the considerable violence in the novel — all of it historically appropriate — leaps off the page. “Like Christ ascending into heaven I felt myself already rising up from the cobbled ground to meet the noose, where another obliging Stasi man, wearing a gray suit and hat, was holding onto a street lamp like Gene Kelly to help lasso my neck with it.” You can’t help but get the picture.

Most of the novel is set in 1939, where Kerr’s picture of daily life in Germany on the brink is hair-raising. People snicker about the hapless Poles. Workers around the Hitler compound are encouraged to shoot cats because the Leader likes birdsong. A sign at the entrance to an Austrian village reads “Jew-free since 1938.”

In the midst of all this lunacy is a rational man known for his “smart remarks.” Such as, “Someone has to do the thinking around here now that the police dogs have been sacked.” And, to an East German VIP, “Tell me, General, when is the communist government going to dissolve the people and elect another?” You have to know that things will rarely turn out well for brave, mouthy Bernie Gunther, but that they turn out at all is exhilarating to watch.

Richard Lipez’s latest Don Strachey mystery, written under the name Richard Stevenson, is “www.dropdead.”

At 7 p.m. on, April 5, Philip Kerr will be at Politics & Prose, 5015 Connecticut Ave. NW.

prussian blue

By Philip Kerr

Putnam. 528 pp. $27.