E. C. Bentley in his milestone detective novel/parody "Trent's Last Case", created Philip Trent, the detective who falls in love with the chief suspect & solves the case quite logically, but with the completely wrong solution. He is only saved with the fortuitous confession of the true murderer. As the authority of (& also author of many) detective stories, Martin Edwards writes, Bentley wrote it as a parody of the "infallible detectives" who had appeared so far, but created a masterpiece of the genre himself. In this Bentley resembles Cervantes, who created "Don Quixote" as a parody of the Chivalry novels then popular, but created an immortal classic by itself.
Similarly, the egoistic Hercule Poirot, a creation of Agatha Christie, in spite of boasting of his celebrated "little grey cells", slipped up badly only once in his career, in the story "The Chocolate Box". Using his twin tools of method & logic, he fixed upon the wrong person as the culprit, only to be saved by the confession of the actual culprit. To his credit it must be said that he analyses & realises himself where exactly he has gone wrong for the first & last time in his career, & even tells Captain Hastings to remind him of it, if he gets too arrogant!