Could you please tell me what should one do if one has accidentally eaten pork? Should he compensate in some way?
When you speak about this happening accidentally, I take it that you mean by genuine mistake, as in the case of a person not knowing that the food contains pork, or that he mistook a word for another when ordering his food in a restaurant, etc. In this case, there is no blame attached to him and he does not need to do anything other than to pray for God’s forgiveness.
The Prophet, peace be upon him, says: “My nation has been forgiven whatever they do through a genuine mistake, forgetfulness, or compulsion.”
Eating pork is forbidden in Islam. If one does it deliberately, one must repent and seek God’s forgiveness. There is no particular form of compensation. However, whenever we slip or make mistakes or commit an offense, it is always proper to follow that with a good deed or more. The Prophet, peace be upon him, says: “Follow a bad deed with a good one so as to erase the former.”