There is a Defense of "Necessity" which would apply in such cases, even if the law had no intent element.. This essentially allows as a defense to an accusation of crime that the actions were essential to prevent harm. Dee, for example Justia's page on The Criminal Defense of Necessity. There it is said:
The defense of necessity may apply when an individual commits a
criminal act during an emergency situation in order to prevent a
greater harm from happening. In such circumstances, our legal system
typically excuses the individual’s criminal act because it was
justified, or finds that no criminal act has occurred. Although
necessity may seem like a defense that would be commonly invoked by
defendants seeking to avoid criminal charges, its application is
limited by several important requirements:
- The defendant must reasonably have believed that there was an actual and specific threat that required immediate action
- The defendant must have had no realistic alternative to completing the criminal act
- The harm caused by the criminal act must not be greater than the harm avoided
- The defendant did not himself contribute to or cause the threat
Only if all of these requirements are met, will the defense of
necessity be applicable. It is also important to note that in some
jurisdictions, necessity is never a defense to the killing of another
individual, no matter what threat they may present.
The Justia page goes on to describe the elements of the defense in detail. See also The Wikipedia artifcel which makes many of the same points.
Necessity is a broader defense than the intent or willfulness requirements of particular laws, because it applied even when the law does nor contain such an element. However, it has its own strict limits, described above. The exact scope of this defense differs in different jurisdictions.