A minced oath, an expression of dismay, disgust, anger, surprise etc.
Used like "what the hell" to add emphasis.
Expressing strong emotion, such as teariness or frustration.