"domesticated or tamed animal kept as a favorite," 1530s, originally in Scottish and northern England dialect (and exclusively so until mid-18c.), a word of unknown origin. Sense of "indulged or favorite child" (c. 1500) is recorded slightly earlier than that of "animal kept as a favorite" (1530s), but the latter may be the primary meaning. Probably associated with or influenced by petty.
Know nature's children all divide her care;
The fur that warms a monarch warm'd a bear.
While man exclaims, 'See all things for my use!'
'See man for mine!' replies a pamper'd goose:
[Alexander Pope, "Essay on Man"]
It is an amiable part of human nature, that we should love our animals; it is even better to love them to the point of folly, than not to love them at all. [Stevie Smith, "Cats in Colour," 1959]
In early use typically a lamb brought up by hand (compare cade); but the earliest surviving reference lists "Parroquets, monkeys, peacocks, swans, &c., &c." As a term of endearment by 1849. Teacher's pet as a derogatory term for a teacher's favorite pupil is attested from 1890. Pet-shop "shop selling animals to be kept as pets" is from 1928.
"fit of peevishness, offense or ill-humor at feeling slighted," 1580s, in phrase take the pet "take offense." Perhaps from pet (n.1) on a similar notion to that in American English that gets my goat (for which see goat), but the underlying notion is obscure, and the form of the original expression makes this doubtful. Perhaps from the notion of "characteristic of an indulged or spoiled child," but OED notes that this word seems to have been originally a southern English term, while pet (n.1) was northern and Scottish. Perhaps influenced by unrelated petulant.
1580s, of an animal, "fondled and indulged," from pet (n.1). Of a thing, material or immaterial, "favored, favorite," by 1826.