Main or not, killing off characters is... the best. It’s a great way to end chapters or even books. However, it takes some skill to make it surprising or deserved.
Choosing the Target
1) Find a protagonist. Anyone will do.
2) Build them up to have a great character arc, a well-rounded personality, lovable, relatable, etc. NOT CLICHÈ.
3) Kill them in the most brutal fashion you can. Make them suffer.
3.5) Kill them at the peak of their arc.
1) Find a villian. Anyone will do.
2) Build them up like you would a protagonist, just... bloodthirsty, controlling, hateful, etc. NOT CLICHÈ.
3) Two options here. Have them kill off your protagonist(s) or let them be beaten in a very quick, easy death. Don’t make them suffer, at least not as much as they deserve.
To Kill a Protagonist
2) Torture, poison, drowing, suffocating, bleeding out (perferably alone), stab/bullet wound in a non-vital place then infection, disease and some more are ways to kill them slowly.
To Kill a Villian
2) Stab/bullet wound in a vital area (doesn’t die right away, but won’t feel much of the pain), disease, suicide (the villian knows what’ll happen; they don’t suffer), execution and more are quicker ways to kill them.