It's thought to have arisen from an amorphous cloud of gas and dust in space. The original cloud was spinning, and this spin caused it to flatten out into a disk shape. The sun and planets are believed to have formed out of this disk, which is why, today, the planets still orbit in a single plane around our sun.