The following story is described in Kojiki (the Records of Ancient Matters) : Izanagi and Izanami used 'Chibiki no iwa' (a huge boulder) as kekkai (barrier) to keep off the pursuers dispatched by the demon when returning from Tokoyo (the world of the dead), and the boulder became associated with iwasaka (the area a deity sits), then the god of the barrier 'Sai no kami' appeared.
古事記はイザナギとイザナミが、常世（とこよ・黄泉の国）から逃げ帰る時に、鬼神の追っ手を防ぐために、「千引きの岩」（ちびきのいわ）を結界として用いたことと、磐境が結びつき、「結界の神」である「賽の神」（さいのかみ・幸の神）がうまれた。