This comes up often enough on knowledge tests and in prep books for the oral portion of practical tests that it should be memorized.
§ 91.3 Responsibility and authority of the pilot in command.
(a) The pilot in command of an aircraft is directly responsible for, and is the final authority as to, the operation of that aircraft.
(b) In an in-flight emergency requiring immediate action, the pilot in command may deviate from any rule of this part to the extent required to meet that emergency.
(c) Each pilot in command who deviates from a rule under paragraph (b) of this section shall, upon the request of the Administrator, send a written report of that deviation to the Administrator.
If two pilots are flying, especially if one is inexperienced, it is important from a legal perspective to decide before taking off who is the PIC.
This rule is intended to allow the pilot to take actions that affect the safety of flight. Avoidance of other aircraft (PDF) and deviation from assigned altitude because of engine problems are examples. You do not have to declare an emergency to rely on this section as a defense or your actions. (PDF). These cases also emphasize that, in hindsight, an emergency may not have to existed, it is the pilots perception that matters.
Part 135 operators are required to report deviations for emergencies § 135.19 Emergency operations.