The 247th mitzvah is that we are commanded to save a person from someone who is trying to kill him, even by killing the attacker. I.e., if there is no other way to save the victim except by killing the attacker, we are commanded to kill him.

The source of this commandment is G‑d's statement1 (exalted be He), "[...if she grabs his attacker by his private parts,] you must cut off her hand [if necessary, to save her victim]; do not have any pity."

In the words of the Sifri: "[The reason the Torah uses the example of] 'his private parts' is because [an attack to] his private parts could endanger his life. In this case 'you must cut off her hand.' So too in any case where his life is in danger, 'you must cut off her hand.' [The reason the Torah says] 'you must cut off her hand' is because you must save him [even] at the cost of her hand. What is the source of the law that if you are unable to save him by cutting off her hand, that you must save him by killing her? The phrase, 'do not have any pity.' "

We have therefore explained the idea of this commandment. The verse2 describes the woman as "the wife of one of the men" fighting because it speaks of the most common case. It conveys the principle that one must save the victim even at the cost of the attacker's limbs, and if it is impossible to save him any other way, you must kill him.

The details of this mitzvah are explained in the 8th chapter of tractate Sanhedrin.3