In a narrower sense, it refers to a person who was a noble or accomplished person in his or her lifetime, but who lost a political power struggle or died prematurely from an epidemic or other disease, becoming an onryō that brings pestilence or famine and is later enshrined as a kami in Shinto shrines.
For example, the "Sandai Jitsuroku" (a historical Japanese document) mentions that six Shinto shrines were dedicated to the worship of goryō, which were the spirits of those who died from non-natural causes.
The belief that the spirits of those who died with resentment or anger after being treated unfairly caused hauntings existed before the Nara period (710–794).
Government official Sugawara no Michizane was killed in a plot by a rival member of the Fujiwara clan.
Even this wasn't enough, and 70 years later he was elevated to the post of Daijō-daijin, and he was deified as Tenjin-sama, which means "heavenly deity".