The central twist of "Knives Out" is that there was technically no murder. Harlan Thrombey did, in fact, commit suicide. The film's brilliance lies in how it frames this fact. The audience is led to believe, along with Marta, that she accidentally gave Harlan a lethal overdose of morphine. To protect her from prosecution, Harlan gives her instructions to create an alibi and then slits his own throat.
The true villain is Harlan's grandson, Ransom Drysdale. After learning at the birthday party that Harlan was leaving his entire fortune to Marta, Ransom devised a plan. He snuck back into the house, swapped the labels on Marta's medicine vials, and stole the antidote, intending for Marta to accidentally kill Harlan. This would make her ineligible to inherit under the "slayer rule," reverting the fortune to the family. However, his plan failed: Marta, through her skill as a nurse, administered the correct medicine by feel, not by reading the switched labels. Harlan would have been fine, but neither he nor Marta realized it in the panic of the moment. His suicide was tragically unnecessary.
Ransom, realizing his plan didn't work as intended, then anonymously hired Benoit Blanc to expose Marta, believing she was guilty. The final act reveals Ransom's further crimes: when the housekeeper, Fran, discovered his scheme, she sent him a blackmail note. Ransom then forwarded a picture of it to Marta to manipulate her, and subsequently gave Fran a near-fatal dose of morphine, burning down the medical examiner's office to destroy the toxicology report that would prove Harlan's innocence and thus Marta's. Marta ultimately tricks Ransom into confessing to Fran's murder on tape, and he is arrested. The film ends with Marta, the rightful heir, looking down upon the disgraced family from the balcony of her new home.