Has this twist ever been used in a mystery novel?

It’s a familiar set up. A murder has occurred. An obvious suspect has been arrested, and faces the death penalty. The evidence against him seems strong. But his mother, sister, or daughter is convinced he’s innocent and asks the great detective to investigate.

The detective starts looking into the case, and quickly discovers a web of secrets and lies. After unravelling it all, the detective gathers all the main characters together, and explains to them what he has discovered: that the obvious suspect was guilty all along.
I don’t count Agatha Christie’s novel Lord Edgware Dies
Although the killer turns out to be the most obvious suspect, the murder happens several chapters into the book, the killer isn’t arrested until the end, and the detective isn’t hired to prove him/her innocent.

Not quite what you were looking for, but in the film Kiss, Kiss, Bang, Bang:

[spoiler]The romantic interest in the film is convinced that her sister’s suicide was actually a murder, and convinces the main character to look into it. Because of this, several other murders are discovered, and the villain’s nefarious scheme is foiled.

But it turns out the sister really did commit suicide, after all.[/spoiler]

It doesn’t precisely match the scenario that you have outlined, but there are parallels in Agatha Christie’s short story:[spoiler]The Witness for the Prosecution.

The protagonist, Leonard Vole, is charged with murder and the case against him looks strong. He seeks the help of renowned barrister Sir Wilfred Robarts to conduct his defence.

Sir Wilfred, after uncovering additional evidence, triumphantly secures Vole’s acquittal. Straight afterwards he discovers that his key evidence was fraudulent and that Vole, now free, is in fact guilty.[/spoiler]

Yes. [spoiler]
That’s pretty much the plot of John Dunning’s The Sign of the Book.

Really, “The Bookman’s Wake” is the only one in the series worth reading.
[/spoiler]

Yep, though not quite in the way you express it. Ellery Queen’s short story “The Case Against Carroll” has Ellery investigating the murder of an old friend’s boss, which the friend is on trial for. As you’ve probably guessed, the friend did do it, and one of the last things he does before he’s executed for the crime is to tacitly beg Ellery not to reveal the truth, lest it shatter the comforting illusions of his wife and family.

How about Agatha Christie’s novel The Hollow, in which the wife who stands to inherit everything is found standing over her cheating husband with a gun in her hand. Did she do it? Of course.

Heck, it’s older than any of these examples. It’s in the Sherlock Holmes story

[spoiler]The Adventure of the Retired Colourman, which is, disappointingly the last one in my Complete Sherlock Holmes. It’s somewhat disappointing for this to be the last Holmes story.

But the premise is that the guilty party himself called in The Great Detective, convinced that he would be fooled, and the morderer would get away with it.
Didn’t work, of course.

[/spoiler]

And how could I forget this example:

Witness for the Prosecution by Agatha Christie, which appeared as a novel, a play, and a movie (with a heckuva cast – Charles Laughton, Elsa Lanchester, Josepg Cotten, and Marlemne Dietrich). Definitely sworth seeing. Charles Laughton’s cigar-smoking attorney trying to sneak his vices past his nanny-like nurse looks like the inspiration for John Mortimer’s Rumpole of the Bailey.

For a twisted variant that follows the exact same structure, there’s Agatha Christie’s novel

[spoiler]After The Funeral, which opens with a bunch of folks inheriting stuff after A supposedly died of natural causes; B pipes up to claim that A didn’t die of natural causes, but was murdered; folks soon take that seriously, as there’s apparently no other motive for the killer who apparently murdered B to silence her later that evening; whoever killed A presumably killed B. So, won’t someone clear the unfairly-besmirched name of natural causes?

Well, no; after a long investigation, Poirot gathers everyone for the summation and explains that A did, in fact, die of natural causes. So who killed B? Well, no one killed B, who is alive and well and standing right here; this whole thing was staged so C’s murder would get everyone asking all the wrong questions.[/spoiler]

In Michael Connelly’s book

The Lincoln Lawyer, it sort of happens. It’s a lawyer, not a detective. Mickey Haller is hired to defend a rich guy accused of murder, and for a while, evidence is mounting that the guy is innocent and being framed. But eventually Haller realizes the guy is in fact guilty, and once the guy realizes that Haller knows, Haller’s own life is in danger. It isn’t a twist that happens at the very end… it happens… hmm, it’s been a long time since I read the book, but I seem to remember it coming maybe midway or 3/4 of the way into the book.

I’d bet that all the classic whodunnit authors pulled this stunt at one time or another. I’m pretty sure that John Dickson Carr did it more than once.

He was a master of deception, but sometimes he flat-out cheated.

[spoiler]Death-Watch starts with this piece of dialogue:

“Boscombe? The murderder?”
“Only the man who admitted he intended to commit murder. As for the real murderer-”

Guess who the real murderer is. Just guess. Probably the most infuriating stunt in all classic mysteries.[/spoiler]

And Cal,

that Holmes ploy was used so often that readers started automatically assuming that the person who called for the detective was the murderer, and writers had to give it up

Exapno – AFAIK, that’s the first and only time Holmes used it. I’m sure that it was a cliche afterwards. I’m not sufficiently familiar with mysteries contemporary with Doyle to know if anyone else pulled this.

I didn’t mean to imply that Doyle re-used it, just that it became a cliche in classic mysteries.

Of course, many of the good ones loved to play with the basics and see how many variations they could squeeze out of them. Queen was like that. Which makes it harder to draw a line between laziness, badness, and inside jokes.

Wheeee! Record for thread with the most spoilers!!

Given the strict wording of the OP – “Has this twist ever been used in a mystery novel?” – I’d like to mention another Agatha Christie story:

[spoiler]The Mysterious Affair At Styles, where Poirot makes his debut by anticipating and countering the twist in question: a young man murders his older wife and plans to pretty much remain silent until standing trial – at which point he’ll grudgingly reveal that (a) he was with another woman way the heck on the other side of town while (b) someone must have been framing him by forging his signature for poison at the druggist’s. (Heck, the mysterious buyer was probably so bundled up that folks only really maybe saw a fake beard and a big pair of glasses, am I right?)

Once he proves he was framed (and he was; that ain’t his signature), the prosecution will presumably drop the case, and cue double-jeopardy protection ever after – except Poirot brings all of the above to light before the trial, clearing the guy’s name and nullifying that twist before the killer can finish using it – thus giving our hero all the time in the world to unravel the remaining secrets and lies before gathering everyone together and revealing whodunnit.[/spoiler]

In the Robin Cook book

Crisis

I don’t remember the specifics but Jack’s brother-in-law really was guilty all along.

I believe Ellery Queen used something similar to this in The Siamese Twin Mystery, but I could be wrong. It’s been years since I’ve read the book and I no longer have it. I also second Leaper’s recommendation. That Queen work is his best short piece, very moody and powerful.

It was also the twist in this relatively recent movie:

Primal Fear, starring Richard Gere and Edward Norton: Primal Fear (film) - Wikipedia.

There are like 1000+ mystery novels published every year, so the really surprising thing would be if this twist had NOT been used. It’s probably used every year.

And then you have the gajilliions of mystery TV shows, mystery and crime movies, etc. It’s really hard to come up with something that hasn’t been done; the thing is do execute one of these plots in an original way. Harder every year.

Not much of a mystery novel reader, but didn’t the Glenn Close/Jeff Bridges film Jagged Edge use this?