It's generally against the law to enter someone's land or use his or her property without permission. If you do, you could be face legal consequences for trespassing.
But there are certain limited circumstances when you can trespass, including emergency situations.
Two commonly used trespassing defenses -- public necessity and private necessity -- may allow you to trespass in an emergency.
A defense to trespass can exist when you (or, more likely, government actors like law-enforcement agents) trespass out of necessity to protect the community or society as a whole during an emergency -- for example, burning down a row of homes to stop the spread of a fast-moving fire.
For this defense to work, there must be an immediate necessity for the trespass and you must have trespassed in genuine good faith that it was to protect public safety. It's meant to protect the public from a greater harm that would have occurred if you had not committed trespass.
Public necessity functions as a complete defense, meaning it shields you from liability for any damages caused by your trespass. But you lose the protection of this complete defense when your trespass becomes unreasonable under the circumstances.
Although not a complete defense, private necessity lets you trespass if it's to protect yourself from death or serious bodily injury in an emergency -- for example, if you're being chased by a dangerous animal and are seeking shelter in someone else's toolshed.
Under the private necessity defense, you are entitled to stay on the land for as long as the emergency continues, even if the owner wants to eject you. However, just like public necessity, you lose the defense's protection as soon as your trespass becomes unreasonable.
Unlike public necessity, private necessity is not an absolute defense to liability for trespass. You may still be civilly liable for any damages that result from your trespass -- for example, if you drove onto someone else's property to avoid an imminent crash and caused $500 in damage to the property owner's fence, you'll probably have to pay for it. But you won't be liable for any nominal or punitive damages.
If you're facing potential legal action related to trespassing, you may want to consult a local real estate lawyer to explore your legal options.