Gravity.
Everything attracts everything else, with gravity.
Image a large amount of rock, floating about until it hits eachother and starts grouping together under gravity. Spinning, too.
Over time, this stuff turns into a spherical shape, because thats the easiest way for it to be (it's most energetically favourable).
Imagine like a cake mixture (loosely speaking) -- just mixing it up, and it tends to form a ball shape. Same kind of thing. It could form a modem of the Eiffel tower, but it's easier to turn into a ball.