Heartburn occurs when gastric contents flow backward from the stomach into the esophagus causing an unsettling and burning sensation behind the sternum or breastbone, either as a contraction or a sharp pain.