Swearing has been proven to mitigate physical pain. Experiments have been done where people were willingly subjected to controlled pain, and some were permitted to swear, while others were not. The neurotransactions associated with sensing pain dropped in those who were permitted to swear just at the point when they actually did swear.
Also, there have been cases where people have had damage to the Broca's area of the brain, so they loose the ability to speak, but they can still swear as much as they want. They understand people speaking to them, and they can converse by writing back, but the only words they can utter are swear words.
Swearing had an evolutionary advantage and that's why it's so prevalent. We are wired up through evolution to have potty mouths. It's actually unnatural to refrain from cursing all of the time. Oh, and if you curse too often, the pain mitigation effect is lost. It only works if you swear when you need it the most.