Do you want to live in a world ruled by law or one where prosecutors can ignore crimes when it suits them?
Deter doesn't actually mean "absolutely prevent". We do want to deter this behavior. We certainly don't want people doing what this guy did on a whim.
When doing something like this you should have to consider that your actions are going to get a hard looking at. Making the case that he did the right thing in front of a court is probably exactly the right venue. It seems like too much discretion for prosecutors to be wielding.
If, hypothetically, at the end of the process he gets convicted because the law doesn't allow a "right thing" defense and it still appears to be a travesty of justice then that's for legislatures and pardon processes to fix.