you were not alone when this happened,don't blame your self . the one you were with must have wished it also, It is what it is.
Hormones and boredom.
I take it that crossing that boundary has had negative consequences? I'm not sure what you do to stop it. You're just following your endocrine system. Practice safer sex is all I can say.