Jagannath Temple was constructed by King Chodaganga. The king started the construction and Jaga mohan or the assembly hall and Vimana or chariot of the temple were constructed during his reign. Later Anangabhima Deva completed the construction of the temple in 1174AD.
A legend says that Indradyumna was a king who worshipped Lord Vishnu very much. Once the king was informed that Lord Vishnu has come in the form of Nila Madhava so the king sent a priest named Vidyapati to search for him. While travelling, Vidyapati reached a place where Sabaras were residing. Vishvavasu was the local chief who invited Vidyapati to live with him.
Vishvavasu had a daughter named Lalita and Vidyapati married her after sometime. Vidyapati noticed that when his father-in-law returns, his body had a good smell of sandalwood, camphor, and musk. On asking his wife, she told him about the worship of Nila Madhava by her father. Vidyapati asked his father-in-law to take him to Nila Madhava. Visvavasu blindfolded him and took him to the cave. Vidyapati took with him seeds of mustard which he dropped on the way so as to remember the route to the cave.
Vidyapati informed the king so he came to the place but, to his disappointment, the deity disappeared. In order to see the deity, he observed fast unto death on Mount Neela. Once he heard a voice saying that he will see the deity so he sacrificed a horse and built a temple and Narada installed the idol of Sri Narsimha in the temple.
One night he slept and saw Lord Jagannath in his dream. He also heard a voice telling him about a fragrant tree and ordered him to make idols from it. So the king made the idols of Lord Jagannath, Balabhadra, and Subhadra. Along with it, he also made the Sudarshan Chakra.
Then the king prayed to Lord Brahma to visit the temple and the deities. Lord Brahma was very pleased when he saw the temple asked about a desire which he (Lord Brahma) can fulfil. The king asked that there shall be no issues in his life and he should be the last one from his family. He also asked that if anybody is left in his family, then he should work for the temple and not the society.
The temple was invaded by many rulers and the count goes to eighteen. The temple was plundered and looted because of enormous wealth present in it. Due to these attacks, the idols of Lord Jagannath, Balabhadra, and Subhadra were transferred to various places in order to save them.
First Invasion − It was done by Raktavahu in the 9th century.
Second Invasion − It was done by Illias Shah who was the Sultan of Bengal.
Third Invasion − It was done by Feroze Shah Tughlaq in 1360.
Fourth Invasion − It was done by Ismail Ghazi who was the commander of Allauddin Hussain Shah, Sultan of Bengal. The invasion was done in 1509.
Fifth Invasion − It was done by Kalapahara in 1568AD.
Sixth Invasion − It was done by Suleman and Osman. Suleman was the son of Kuthu Shah whereas Osman was the son of Isha, the ruler of Odisha.
Seventh Invasion − It was done by Mirza Khurrum, the commander of Islam Khan. Islam Khan was the Nawab of Bengal. The invasion was done in 1601AD.
Eighth Invasion − It was done by Hasim Khan in 1608AD. Hasim Khan was the Subedar of Odisha.
Ninth Invasion − It was done by Kesodasmaru who was a jagirdar and a Hindu Rajput.
Tenth Invasion − It was done by Kalyan Malla, son of Raja Todar Mall. It was done in 1611AD.
Eleventh Invasion − It was also done by Kalyan Malla in 1612.
Twelfth Invasion − It was done by Mukarram Khan in 1617AD.
Thirteenth Invasion − It was done by Mirza Ahmad Beg who was the nephew of Nurjahan, wife of Jahangir.
Fourteenth Invasion − It was done by Amir Mutaquad Khan in 1641AD.
Fifteenth Invasion − It was done by Amir Fateh Khan in 1647AD.
Sixteenth Invasion − It was done by Ekram Khan, the Nawab of Odisha. The invasion was launched in 1699.
Seventeenth Invasion − It was done by Muhammad Taqi Khan in 1731.
Eighteenth Invasion − It was done by the followers of Alekh religion in 1881.