Necessity (criminal law)

In the criminal law of many nations, necessity may be either a possible justification or an exculpation for breaking the law. Defendants seeking to rely on this defense argue that they should not be held liable for their actions as a crime because their conduct was "necessary" to prevent some greater harm and when that conduct is not excused under some other more specific provision of law such as self defense. Except for a few statutory exemptions and in some medical cases there is no corresponding defense in English law for murder.
For example, a drunk driver might contend that they drove their car to get away from being kidnapped (cf. "North by Northwest"). Most common law and civil law jurisdictions recognize this defense, but only under limited circumstances. Generally, the defendant must affirmatively show (i.e., introduce some evidence) that (a) the harm they sought to avoid outweighs the danger of the prohibited conduct they are charged with; (b) they had no reasonable alternative; (c) they ceased to engage in the prohibited conduct as soon as the danger passed; and (d) they themselves did not create the danger they sought to avoid. Thus, with the "drunk driver" example cited above, the necessity defense will not be recognized if the defendant drove further than was reasonably necessary to get away from the kidnapper, or if some other reasonable alternative was available to them.
General discussion.
As a matter of political expediency, states usually allow some classes of person to be excused from liability when they are engaged in socially useful functions but intentionally cause injury, loss or damage. For example, the fire services and other civil defence organizations have a general duty to keep the community safe from harm. If a fire or flood is threatening to spread out of control, it may be reasonably necessary to destroy other property to form a fire break, or to trespass on land to throw up mounds of earth to prevent the water from spreading. These examples have the common feature of individuals intentionally breaking the law because they believe it to be urgently necessary to protect others from harm, but some states distinguish between a response to a crisis arising from an entirely natural cause (an inanimate force of nature), e.g. a fire from a lightning strike or rain from a storm, and a response to an entirely human crisis. Thus, parents who lack the financial means to feed their children cannot use necessity as a defense if they steal food. The existence of welfare benefits and strategies other than self-help defeat the claim of an urgent necessity that cannot be avoided in any way other than by breaking the law. Further, some states apply a test of proportionality. So the defense would only be allowed where the degree of harm actually caused was a reasonably proportionate response to the degree of harm threatened. This is a legal form of cost–benefit analysis.
Specific jurisdictions.
Denmark and Norway.
Emergency law/right ("nødret", "nødrett") is the equivalent of necessity in Denmark and Norway. It is considered related to but separate from self-defence. Common legal examples of necessity includes: breaking windows and other objects in order to escape a fire, commandeering a vehicle to serve as an emergency ambulance, ignoring traffic rules while rushing a dying patient to a hospital, and even killing a person who poses an immediate threat to several other people not including yourself. In the last case self-defense laws are not enough, but the case is covered by "nødret". "Nødret" can only be invoked though when no other option is available.
International law.
Customary international law.
Under international law, an obligation of customary international law or an obligation granted under a bilateral investment treaty may be suspended under the doctrine of necessity. It is "an exception from illegality and in certain cases even as an exception from responsibility." See "Continental Casualty Company v Argentine Republic, ICSID Case No ARB/03/09." 
In order to invoke the doctrine of necessity:
Switzerland.
In two separate cases in 2020, climate activists were not convicted of trespassing and damaging property after holding unauthorized demonstrations in Crédit Suisse branches due to pleading a necessity defense in the face of a climate emergency.
Taiwan, Republic of China.
Necessity is a possible defense per the Criminal Code and the Administrative Penalty Act.
United States.
Necessity as a defense to criminal acts conducted to meet political ends was rejected in the case of "United States v. Schoon". In that case, 30 people, including appellants, gained admittance to the IRS office in Tucson, where they chanted "keep America's tax dollars out of El Salvador," splashed simulated blood on the counters, walls, and carpeting, and generally obstructed the office's operation. The court ruled that the elements of necessity did not exist in this case.
Singapore.
Necessity is a defence per the Penal Code.
This requires lack of criminal intent, good faith (due care and attention), and the goal of preventing harm. The harm must be sufficiently serious and imminent to justify or excuse the act.
Canada.
In Canada, Necessity is recognized as a defence for crimes committed in urgent situations of clear and imminent peril in which the accused has no safe or legal way out of the situation. 
Three Requirements for defence of necessity:
(1) Urgent situation of imminent peril or danger 
(2) No reasonable legal alternative
(3) Proportionality between harm inflicted and harm avoided
The first and second element are evaluated on the modified objective standard. The third element is evaluated on a purely objective standard. R v Latimer, 2001 SCC 1
In religious law.
In Judaism, the principle of "pikuach nefesh" allows any law to be broken to save a life, except laws against murder, adultery/incest and blasphemy/idolatry.