The story you are talking about, “The Final Problem”, was created absolutely to kill Holmes because Doyle was beginning to realize that his other literary work was being overshadowed by Sherlock Holmes.
He famously said “I must save my mind for better things, even if it means I must bury my pocketbook with him.”.
He was…