According to mythology, Ravana sought help from his brother Ahiravan as soon as he realized that he has been defeated by Lord Rama in war.
When Ravana asked for his help, Ahiravan laid a trap and put all of Lord Rama's associates to sleep. He then took Lord Rama and Lord Lakshman as captive, and took them to Paatal Lok (the underworld).
As soon as Vibhishan regained consciousness, he understood all of Ahiravan's tricks and asked Lord Hanuman to go to Paatal Lok and rescue Lord Rama and Lord Lakshmana.
On reaching Paatal Lok, Lord Hanuman first defeated Makardhwaj and then approached Ahiravan.
Ahiravan was so blessed that he could be killed by only one who could extinguish 5 lamps lit by him at once.
Taking advantage of this, Ahiravan burnt lamps in all 5 directions. Seeing this situation, Hanuman took the Panchmukhi form and extinguished all five diyas at once.
He then succeeded in killing Ahiravan. From then on, Lord Hanuman's Panchmukhi form began to be worshipped.
Lord Hanuman's Panchmukhi (Five-Faced) Avatar is said to represent all five directions. His five faces are considered to represent East, West, North, South and Upper directions.
Lord Hanuman Eastern face is that of a monkey, which is said to have the brightness of a thousand suns.
Lord Hanuman's Panchmukhi Avatar has five faces, those of a lion, eagle, horse, monkey and varaha form.