The story of Vishnu worshiping Ganesha is given in Chapter 18(pg 205) of Ganesha Purana Upasanakhanda. Since the story is a bit long I'm referencing only relevant parts of it.
The story begins with Madhu Kaitabha, two demons formed from Vishnu's ear wax. It follows a similar vein from various Puranas. The demons try to attack and eat Brahma who prays to Vishnu for help. Vishnu awakens from his Yoga Nidra and fights the two demons but is unable to defeat them. The battle lasts 5000 years!
A confused Vishnu goes to Lord Shiva for advice whereby the Lord tells him he wasn't able to defeat Madhu-Kaitabha because he forgot to adore Vinayaka before the battle. Vishnu asks how he can rectify his mistake. Lord Shiva initiates him in an Eka-akshari and Shoda-akshari Ganesha mantra.
Bhirgu said, Hari then told him about the previous course of events
concerning the two demons Hari said, Whilst I was asleep on the ocean
of milk, Madhu and Kaitabha arose from my ear secretions and came to
eat Brahma. Brahma eulogized Sleep, splendid Siva, and she awakened
I then engaged in battle with those two and a wrestling match ensued.
I was unable to conquer them so I did this.
Now, Siva, repository of compassion, tell me the way to kill them.
Siva said, You went to the battleground without having worshipped
Vinayaka, and so you had no strength. Consequently, you have got real
After you have worshipped Ganesa, set out for battle, respectable god!
With his power of illusion he will delude those two and through my
favour you will kill those two malevolents. There is no doubt of it!
Hari said, Siva, tell me, how I should worship that god, Vinayaka?
Isvara said, There are seven myriads of Ganesa mantras which have been
recited. Even amongst them there are great mantras and even amongst
them there is a great one-syllable mantra and a six syllable one.
Illustrious Visnu, I am going to tell you about one of these two.
Then, having set aside the one syllable mantra in consideration of the
power of his discus and the Siddhari mantra, and having paid out a
monetary debt, he told him that great six syllable mantra of Ganesa
which is auspicious and grants every success. Merely by performing it
your task will be successful. Then Visnu left quickly to perform it.
Vishnu goes to Siddhiksetra and performs penance for a 100 years after which Ganesha appears before him and grants him boons.
The King said, How and where did Visnu recite that excellent mantra
and did he obtain success? Tell me this in detail! The sage said,
There is a celebrated place of the highest quality called Siddhiksetra
which gives success on the earth. After going there the great Visnu
performed a severe austerity. Whilst meditating on Vinayaka he
propitiated that god in accord with the procedure for the six-syllable
After a period of one hundred years had passed, the supreme self,
Ganadhipa, who was like a myriad of suns and fires, became visible.
Completely tranquil in heart, he spoke to Visnu, on whose banner is
Garuda. Ask me for those boons that you want, Visnu. I will give them
all because I am satisfied with your austerity. If I alone am
worshipped first, victory will certainly be yours.
By seeing one like you I will experience success in all things, god.
However, I am still going to tell you about one thing. At the end of
my yogic sleep Madhu and Kaitabha sprang up from the dirt in my ears.
These two great warriors strove to eat Brahma. Then I fought with them
for many days, but because my strength is waning I have come to you
So think about how I will destroy these two, as the highest renown
exists in victory over other demons. Supreme Lord, give me now your
inexhaustible devotion, through which my unmatched fame will cleanse
Ganesa said, Visnu, you will certainly get whatever you request. You
will have glory, strength, the highest fame and no obstacles.
After this, Vishnu establishes an idol of Ganesha at Siddhiksetra which was known as Siddhivinayaka. Today this ksetra is known as Siddhateka which houses the famous Ashtavinayaka, Siddhivinakaya.
The Sage said, Having said this to the great Visnu, Lord Ganesa
disappeared from there, but Visnu was filled with joy as he considered
these two demons to be conquered.
There he built a crystal palace which was rich with jewels, a
glittering gold spire and four very splendid domes. Then he set up an
image made of jewels taken from the Gandakiya river.
The gods and sages spread its fame under the title Siddhavinayaka,
since Hari obtained a splendid success there. Thereafter, it became
famous as Siddhiksetra, the field of success all over earth.