No one truly knows how or why animals were domesticated, but there are two basic theories. The second theory is that they were companions first, and helpmates later. According to theory number one, it was almost an accident that they later became our companions. But our ancestors were human, and humans tend to find comfort in being with other living beings. From the pet's point of view, humans seem to make pretty good company.
Most animals are social by nature.
The ancestors of dogs were pack animals with highly developed social organizations. Cats and even small animals, like hamsters and guinea pigs, live in complex hierarchical colonies in the wild. Domesticated pets are the kind of creatures who need people, and for the most part, they benefit from their relationship with us, not only mentally but physically. Recent studies show that in both dogs and horses, heart rate and blood pressure decrease during grooming or petting. And whatever their original purpose, pets have now found their way firmly into our hearts and homes.