As a concept? DeSade I imagine. Wrote enough about it to have the term coined after him. And Sacher-Masoch for the flip side.

But as far as how it came to be? The origins of it?
Well the need to dominate and be dominated goes back to the cave imo.
Someone leads, someone follows. Learning how to get along within the group... what we might today call tough love except it includes getting cuffed (hit) with the back of the hand when we make mistakes lest we don't take the lesson seriously...

Yeah, I think it's built into us. 'Modern' social ethics and mores (religions) have drawn us away from our baser instincts.