It varies by class. Hunters start with a pet and can tame additional ones at level 10. Warlocks get theirs at level 1. Enhancement shamans pick up spirit wolves at 60, and death knights acquire their pet at 55.
Companions are different — you buy those from vendors or the auction house. One vendor sits in Elwynn Forest, south of Northshire Valley, but there are vendors scattered all through Azeroth, so it's rarely worth travelling far for one.