Why the #$% Do We Swear? For Pain Relief
scientificamerican.com
scientificamerican.com
"When swearing, the 67 student volunteers reported less pain and on average endured about 40 seconds longer."
As to the "why"/mechanisms... just the authors' speculations at this point.