Vedic Gods always exists.
They show themselves based on a devotees Sadhana or their requirement in a cosmic situation in sustaining the universe.
Most of stories in Purans have happened a number of times in different Kalpas and Yugas with some Variations. These have happened already and even Will happen in the future again and again.
So coming to question: There were 3 Asuras who were Son's of Tarakasura.
Tarakaksha, Kamalaksha and Vidhyunmali
They performed Thapas and as a boon got 3 fully facilitated and equipped Cities made of Gold, Silver and Iron. All three have the ability to fly in Space and never come in a straight line.
So their condition for their Death Wish was. The Man who is King of all Gods. Should come on a chariot that never existed, A Bow that was never built and an with an Arrow that was never made before. Using these tools the King of Gods should hit the three Cities when they come in one straight line.
So Bhrama, Indra and other Gods made bought the essence of 14 lokas into Earth and made it as chariot. The power of Sun and Moon as two wheels. 4 Vedas as horses. Bhrama as the coach man. Pranava [Om] As a whip.
They made Meru Parvatha (Golden Mountain) as bow and Adhisesha as the Bow string. Vishnu + Agni + Soma became an Arrow.
Invited Shiva and requested him to get on the chariot and finish the Demon Kings.
So Shiva has entered the chariot reached into space and waited for a long long time for the three Cities to come in one straight line which they never came. After thinking for himself Shiva Realized that He has to please Ganesha for this obstacle to be removed.
So Shiva sat in a meditative position and went deep inside. After a while from the 5 Faces of Shiva came out a light and formed a 5 Elephant headed Boy with three eyes on each face and Moon on each crown. Shiva opened his eyes and both smiled and each other.
Shiva pleased Ganesha with a 1000 names which famously available as Ganesha Sahasranamam. Useful for Sadhana for Ganesha's devotees. Then Ganesha promised that this time the three Cities will come into a line.
Shiva went back and stood on the chariot with his Bow and Arrow. Ganesha invisibly grew his Trunk and make three space Cities hold in one straight line. Shiva shooted Vishnu in the form of Arrow and the Asura, thier followers and the three Cities burnt to Ashes within seconds.
This is the instance through Shiva - Ganesha showed his Panchamukhi Form.
In Mantra Shashtra this form is called as “Herambha Ganapathi”. Herambha - means
Deenaradha vachako Hescha, Rambha palaka vachakaha! Palakam deenalokanam Herambham pranamamyaham!!
Which means he is the God who protects the weak and helpless.
Sri Ganeshaya Namha