All that G‑d created, He created for His glory. (Avot 6)

The main reason why there arose a thought to create all universes was only because of Israel, His holy people, in order that they should worship Him and give Him pleasure. Existence is granted to all worlds primarily for the sake of His worship, so that we should be able to worship Him.

Actually, the main purpose of Creation was so that we should worship G‑d. This raises a very strong question regarding those who do not do G‑d's will. How do they also have existence? A king builds a great palace for his children…

This can be explained with an example: A king builds a great palace for his children. The king himself does not need this building, and the only reason he builds it is for the sake of his children. After the building is complete, an enemy of the king's children wants to live in it. The king then looks at the root of his thought, the reason why he decided to build this palace. He himself did not need it, and the main reason that he had a thought to build it was for the sake of his children. When the king concentrates on this thought, he certainly will not let any of his children's enemies live there. He will permit no one other than his children to live in this palace, just as he decided in is original thought.

But when the king does not pay attention to his original thought that the palace was only built for the sake of his children, then another can also live in it.

The same is true of the Creator. The primary Original Thought to create all universes was for the sake of the souls of Israel. When the Creator gazes at the Original Thought, then He gives sustenance only to Israel and the universes that do His will. But when, heaven forbid, the Creator does not pay attention to the Original Thought, then even those who do not do His will receive sustenance.

This is the concept of the miracles that were done for Israel. All miracles result from when the Creator gazes at His Original Thought…

This is also true of the redemption. G‑d will gaze at His Original Thought and through this, we will be redeemed.

[from Kedushat Levi by Rabbi Aryeh Kaplan, p. 160
The Chasidic Masters, Moznaim Press]