There’s kind of alot going on, but the shortest answer is “the electrostatic force between the positive nucleus and negative electron creates orbits in the same way that gravity allows a moon to orbit a planet”. The electron is moving fast enough that it just “misses” the nucleus. At least, from a classical lens.
It gets more complicated when you introduce orbital angular momentum and start considering the magnetic effects of moving charges, and that’s what leads to the funky non-spherical orbital shapes.