The Transcendent Wisdom Scripture for Humane Kings Who Wish to Protect Their States, also known simply as the Sūtra of Humane Kings, states:
"Great king! In all states there are countless specters and spirits, each of whom has countless minions. If they hear this scripture [Sūtra of Humane Kings], they will protect your state. If a state is on the verge of chaos, the specters and spirits form the vanguard of chaos. Because of the chaos of the specters and spirits the myriad people become chaotic. In due course bandits arise and the one hundred surnames perish. The king, the heir apparent, the princes, and the one hundred officers involve one another in scandals.
I open with this excerpt from the Sūtra of Humane Kings not because of its benefit specifically but to make a point and emphasize the benefit of the Buddhadharma for societies that uphold it. Case in point, the aforementioned text was edited and taught by the Buddhist monk Amoghavajra (Chinese: 不空, Bùkōng) specifically for the benefit of the Táng dynasty in China. He formulated rites based on this text in order to safeguard the nation from strife, rebellion, famine, and other misfortunes. It is claimed that he was able to preempt the Tibetan and Uygher invasion in 765 through these rites, leading to the dispersion of said force.
In Japan, during the Heian period, the monk Kūkai intentionally went to China to learn Esoteric Buddhism (密教, mikkyō) in order to benefit the nation. Kūkai spent his entire life propagating Buddhism and serving the nation and the Japanese imperial court. He would perform rites to end droughts (i.e., bring rain), expounding scriptures to end epidemics and calamities, conduct preside over state rituals. Kūkai inherits his methods from the same line as that of Amoghavajra through the latter's student Huìguǒ.