It pre-dates recorded history. The Ancient Greeks did it, so did the Romans and the ancient Chinese were doing it around 5000 B.C. as well. Plus, interestingly enough, the Nuer tribe in Sudan allow for same-sex marriage too.
Basically, it's been around since before the traditional institutions...