Legend has it that the shrine was founded in the year 876 when the divided deity Gozu Tenno (Susanoo no mikoto) was transferred from Hiromine-jinja Shrine in Harima Province and a Chineki-sai (ritual to dispel evil spirits) was held during which the portable shrine in which the deity was being transported was placed and enshrined in a forest in Nagi.
貞観(日本)11年（876年）、播磨国広峰神社から牛頭天王（素戔嗚尊）を勧請して鎮疫祭を行った際、牛頭天王の分霊をのせた神輿を梛の林中に置いて祀ったことに始まると伝えられる。