That’s the law in almost all civilised countries,
No it is not.
For example, in Germany, the rule is necessary defense. Was the level of defense necessary to defend yourself. If you sleep with a gun under the pillow, the "mildest necessary defense" is shooting the home invader. If you had to go to your neighbour to borrow said gun, come back and then shoot them, that would be breaking the law.
See https://se-legal.de/services/criminal-defense-lawyer/self-defense-in-germany/?lang=en
(Sorry its some random lawyer practice, but it in English and I don't want to scour the internet on Friday)