You may well have heard the story of Taira no Masakado who hailed himself as the new emperor and started a revolt before being killed at the Battle of Kojima in 940. His decapitated head was taken to Kyoto where it was put on display as a warning to anyone else that might have like ideas above their stations. It wasn't long though before the bloody head began screaming "Where is my murdered body!! Where is my murdered body!!", after which it disappeared to reappear in what is now Tokyo. The tale from there continued on and the legend of the Curse of Masakado was built over the centuries that followed.
But there is also another tale connected to Masakado that involves an unhappy spirit. The character in question in this story is Fujiwara no Tadafumi.
Fujiwara no Tadafumi (873-947), also known as Uji Minbu-kyo, was appointed as a general (given the title Taishogun - Commander General of Eastern Forces) and sent with his forces to join the fight against Taira no Masakado. By the time Tadafumi arrived at the battle it was already over and Masakado was dead. The revolt was over.
After the battle and when it was time for the regent, Fujiwara no Saneyori, to hand out the rewards to those who had helped, Fujiwara no Tadafumi was overlooked. Fujiwara no Saneyori's younger step-brother, Morosuke, (with the quote that he is said to have remarked "When in doubt about the offense, consider giving the lighter sentence; and when in doubt about the merit, consider giving the higher award") tried to convince Saneyori to think again but he was having none of it. Fujiwara no Saneyori was adamant that as Tadafumi had not been involved in the battle to defeat Taira no Masakado then he deserved nothing. The bitter Tadafumi died just 7 years after the Battle of Kojima and his angry spirit was said to have haunted the family of Fujiwara no Saneyori thereafter.
The death of both Saneyori's daughter and eldest son were blamed on the vengeful spirit of Tadafumi. In an attempt to appease the spirit of Tadafumi, this small shrine, Matafuri Shrine was built. The shrine is located close to the World Heritage site of Ujigami Jinja, within walking distanc eof Uji Keihan Station.