According to legend, the construction of the first Jagannath temple was commissioned by King Indradyumna, son of Bharata and Sunanda, and a Malava king, mentioned in the Mahabharata and the Puranas.
The legendary account as found in the Skanda-Purana, Brahma Purana and other Puranas and later Odia works state that Lord Jagannath was originally worshipped as Lord Neela Madhaba by a Savar king (tribal chief) named Viswavasu. Having heard about the deity, King Indradyumna sent a Brahmin priest, Vidyapati to locate the deity, who was worshipped secretly in a dense forest by Viswavasu. Vidyapati tried his best but could not locate the place. But at last he managed to marry Viswavasu's daughter Lalita. At repeated request of Vidyapti, Viswavasu took his son-in-law blind folded to a cave where Lord Neela Madhaba was worshipped.
Vidyapati was very intelligent. He dropped mustard seeds on the ground on the way. The seeds germinated after a few days, which enabled him to find the cave later on. On hearing from him, King Indradyumna proceeded immediately to Odra desha (Odisha) on a pilgrimage to see and worship the Deity. But the deity had disappeared. The king was disappointed. The Deity was hidden in sand. The king was determined not to return without having a darshan of the deity and observed fast unto death at Mount Neela, then a celestial voice cried Thou shalt see him. Afterward, the king performed a horse sacrifice and built a magnificent temple for Vishnu. Narasimha Murti brought by Narada was installed in the temple. During sleep, the king had a vision of Lord Jagannath. Also an astral voice directed him to receive the fragrant tree on the seashore and make idols out of it. Accordingly, the king got the image of Lord Jagannath, Balabhadra, Subhadra and Chakra Sudarshan made out of the wood of the divine tree and installed them in the temple.