There’s another mantra also that can be recited. You have to recite it loudly, not quietly, but with sound, so the spirits can hear it. Then they won’t harm you. They are so happy with you and they respect you.

From the Sorrowless Sutra, the Kha-ba:

When Ananda was attacked by the 64,000 maras, as Buddha gave this mantra to the Bodhisattva Manjugosha, this mantra was announced. When the king of the maras heard it he generated bodhicitta, the thought of enlightenment, and the king of the maras let go of Ananda.

This is the mantra Abandoning Completely the Actions of Mara taught by Buddhas equaling the number of the sand grains of the ten times Ganga water. Devas, nagas, smell-eaters, asuras, nagading floating in the sky, myemchi, Toche Chenpo, the divisions of eight worldly devas, then human beings, non-human beings, devas abiding on the mountains, trees, waters, lake and families place, the minute they hear this mantra they keep the name of that person and respect that person. [That person will] also abandon [taking a] woman’s body, remember their past life, engage in celibacy, not eat wine, meat and so forth, and like solitude. If one recites this with devotion or writes it in scriptures, it purifies 77 x 100 billion negative karmas, non-virtuous actions. This mantra is said to have those benefits:

AMA LAI, PEMA LAI, NIR MA LAI, MOOGA LAI HAI, MALA ZA GHA GAI, GHA GAI, TSAMANTRA BAR TAI, SHAWA TA SA TEN NAI, BRAMA ATA TSA RA NAI, MA NA TSAI, ASHU DAI, PILA GI, AMA LAI THE, PA LAM ME, PA LAM PHA SWA RE, PUN NAI PUN NAI, MAN NO LA DE