The Solar System formed from a rotating cloud of interstellar matter about 4.6 billion years ago.
This cloud, upon condensing, collapsed under the influence of gravity and flattened into a rotating disk.
The sun, planets, and moons formed within this disk