The doctrine of necessity is a legal principle that permits an individual to act in a way that would otherwise be unlawful, in order to prevent a greater harm or to safeguard an essential interest. This doctrine is often applied in emergency situations where immediate action is required to avoid significant harm, and it can serve as a defense against claims of tortious conduct.