As October is drawing to a close, this will be my last, for a bit, more supernatural-themed Heian entry.
Imagine a modern country and a modern bureaucracy. Depending on your government type, you have various ministries and our departments/ministries dedicated to the various functions expected of government: education, defense, civil affairs, et cetera. Bureaucrats and government officials populate these departments and ministries trying (we'll think positively here) to do their part to keep their respective functions running smoothly so that their respectively countries will run smoothly.
Maybe somebody doesn't grow up thinking, "My goal in life is to work in the Department of Agriculture" (or maybe they do), but in the end, they get their university/academy education, take their appropriate exams, and end up a government functionary.
In a sense, the Heian-era government wasn't really all that different. Although it never really functioned as the meritocracy certain aspects of the system would suggest (and I'm definitely not saying modern governments always manage that), the Heian-era system was still basically defined by taking educated people, applying sort of testing/filtering, and placing them into positions to help run the government. So, in that sense, the government of the Heian era doesn't really seem that foreign.
Now imagine your cousin went to work for the government and told you he was going to work in the Department of Divination. Imagine he told you that his job was going to advise the president on days were lucky and what path he should take if he left the White House to avoid unlucky circumstances. Maybe, just maybe, your cousin is even going to be called out to help lay out a new governmental facility to help it avoid bad spiritual flow or exorcise a few rogue spirits.
Science, religion, and mysticism weren't as separated for the people of the Heian era as they are for many people today. Indeed, what we would consider nothing but superstition often was looked at as one of the best ways to know about the world. Although there were governmental agencies dedicated to the management of Shinto ritual and the occasional angry spirit, the curious mix of the pragmatic and the supernatural was particularly embodied by the onmyō-ryō (lit. the bureau of Yin and Yang, but often referred to as the bureau of divination).
This governmental agency was filled with onmyōji, practitioners of the semi-mystical art of onmyōdō (lit. The way of Yin and Yang). The onmyōji are a perfect example of Japanese syncretism. They combined elements of Chinese cosmology, native Shinto beliefs, Buddhism, and even elements of Indian astrology. Now while sometimes they are treated as if they were all-purpose magicians (the ability to summon a type of servant spirit, shikigami, is and was still associated with them), these government mystics actually tended toward more specialization in their jobs. This actually makes sense, if you think about it, as the existence of entire Buddhist priesthoods and Shinto-related government departments suggests that one type of magician wasn't going to cut it for the needs of the people.
Broadly speaking, the onmyōji's main duties can be divided into determination of auspiciousness (I'll expand on this in a moment), divination, and keeping track of the calendar. Although they were sometimes called to aid with exorcisms and the like, the plentiful number of Buddhist and more-dedicated Shinto religious personnel arguably got the lion's share of that sort of work, at least judging by period fiction and diaries. Conversely, restrictions on the ability of Buddhist priests, in particular, to practice astrology and divination (for the most part) left an opening for the onmyōji to gain firm control over these aspects of court life.
The calendar aspect is particularly interesting. We take it keeping track of time for granted in the modern era, but this was a specialized skill in the Heian era. In fact, for many centuries, it was even more specialized with a particular clan, the Kamo, becoming primarily responsible for calendar maintenance. One of the most famous onmyōji of the period, Seimei Abe (Abe no Seimei, 921-1005) who trained under the premiere master of the age was supposed to be so skilled that he became responsible for the more "important" skills of divination and astrology, while the son of his master was given instead the lesser task of calendar construction and maintenance. Arguably the latter probably ended up more important in the long run for the Heian government.
Besides the practical value in maintaining a calendar, it aided with the determination of things such as auspicious days. The aristocracy were obsessed with the concept of auspiciousness. There were auspicious days, auspicious numbers, and auspicious directions along with their inverse. Having a good calendar system aided in keeping track of this sort of thing, especially when combined with astrology. In addition, a good calendar was important in helping to keep track of the huge number of festivals and ceremonial days that defined aristocratic court life.
This auspiciousness obsession was at the basis of the popularity of onmyōji. Though straight-forward divination questions (such as finding lost objects) were part of their techniques, the more indirect ability to advise people, particularly the nobles, on the various auspicious/inauspicious aspects of their life was more their stock and trade. This could have rather permanent impacts on even city layout, as they also advised the government and aristocrats on building position, layout, direction, and the like (similar in style to feng shui) to help maximize auspiciousness.
Sometimes this obsession with such concepts could lead to strange behaviors (strange to moderns anyway) that put certain aspects of period fiction into a more understandable framework. For example, more than a few piece of period fiction have a gentleman not taking the most direct way home and running into some sort of mischief (supernatural or otherwise) because of it. This is a reflection of receiving information about inauspicious directions from an onmyōji. It's common enough in period fiction, and period diaries also reflect that this sort of extreme adherence to these beliefs definitely impacted the lives of many aristocrats.
I could fill a whole blog series on the onmyōji, so I'll just close by stressing that despite the fact that many of their methods were more magical and esoteric in style, these men were part of the respected educated bureaucratic elite and were treated with the respect that many scientists are treated today. These were not fringe mystics. At the same time, these men's abilities were considered distinct from the religious and spiritual powers associated with Buddhist priests and Shinto priests and priestesses.