Necessity is a legal doctrine that allows a person to take actions that would otherwise be considered illegal if those actions are taken to prevent a greater harm from occurring. This principle is used as a defense in criminal law and tort cases, where the individual argues that their unlawful conduct was justified because it was essential to avert an imminent danger. Understanding necessity helps clarify the balance between lawful behavior and the exigencies of urgent situations.