It happens... During orgasm, the pelvic floor muscles contract and relax rapidly. This can override the normal level of tone that the anal sphincter usually maintains. It's usually not a problem. However, if there is some loose stool or a small piece of formed stool in the rectum, it may just come out. Try adding a daily insoluble fiber supplement to your diet, and try moving your bowel sbefore sex if possible.
Move bowels before. This is uncommon. Do you have loss of bowel control or loss of gas normally? If not, you may have very powerful contractions of your muscles around the rectum during orgasm. Moving your bowels before sex may help (not like one always plans so far in advance!). If it persists, you may wish to see a gastroenterologist to make sure there is no illness of the rectum. Good luck!