PAN (Παν) was the god of shepherds and flocks, of mountain wilds, hunting and rustic music. He wandered the hills and mountains of Arkadia playing his pan-pipes and chasing Nymphs. His unseen presence aroused feelings of panic in men passing through the remote, lonely places of the wilds.
The god was a lover of nymphs, who commonly fled from his advances. Syrinx ran and was transformed into a clump of reeds, out of which the god crafted his famous pan-pipes. Pitys escaped and was turned into a mountain fir, the god's sacred tree. Ekho spurned his advances and fading away left behind only her voice to repeat forever the mountain cries of the god.
Pan and Syrinx by Jean François de Troy
Pan was depicted as a man with the horns, legs and tail of a goat, and with thick beard, snub nose and pointed ears. He was often appears in the retinue of Dionysos alongside the other rustic gods. Greeks in the classical age associated his name with the word pan meaning "all". However, it true origin lies in an old Arkadian word for rustic.
Pan was frequently identified with other similar rustic gods such as Aristaios, the shepherd-god of northern Greece, who like Pan was titled both Agreus (the hunter) and Nomios (the shepherd); as well as with the pipe-playing Phrygian satyr Marsyas; and Aigipan, the goat-fish god of the constellation Capricorn. Sometimes Pan was multiplied into a host of Panes, or a triad named Agreus, Nomios, and Phorbas.
Pan strikes me as less of a 'god' of shepherds and perhaps more like the nature spirits that he likes to chase, just in a masculine form. As with centaurs, does this mixing of man and animal form simply a bestial creature driven by lust and base desire? Pan is linked with Dionysos and his Maenads also fall into this bestial behaviour when under the influence of their god.
Perhaps with the image of Satan and/or Baphomet taking on the goat legs and horns, this was a way of trying to demonise this wild ecstasy (from the Greek ekstasis, meaning 'outside of one self') that one could achieve from communion with the god.