The Prayer to Saint Michael the Archangel is the result of a mystical vision of Pope Leo XIII sometime between 1884 and 1886. When he had just finished celebrating Mass, he had a vision in which he saw demons gathering in Rome and heard the devil boasting that he could destroy the Church and demanded sufficient time to do so.
When Pope Leo came out of his mystical vision, he immediately went to his desk and wrote down what we now know as the Prayer to St. Michael the Archangel. He decreed that it should be said at every daily Mass offered in the Catholic Church throughout the world as a response to the demonic agenda of Satan and his minions. The Church greatly encourages the faithful to pray this prayer as a protection from spiritual evil in our world.