On one occasion Bacchus, in his Indian expeditions, was encompassed with an army far superior to his own; one of his chief captains, named Pan, advised him to command all his men at the dead of night to raise a simultaneous shout. The shout was rolled from mountain to mountain by innumerable echoes, and the Indians, thinking they were surrounded on all sides, took to sudden flight. From this incident, all sudden fits of great terror have been termed panies. (See Judges vii. 18-21.)
Theon gives another derivation, and says that the god Pan struck terror into the hearts of the giants, when they warred against heaven, by blowing into a sea-shell.
Source: Dictionary of Phrase and Fable, E. Cobham Brewer, 1894
More on Panic from Fact Monster: