Why were dogs domesticated?

Humans and wolves lived side by side for millennia before we turned them into dogs. So what changed? Why were dogs domesticated after co-existing for so long?