A simple answer to what keeps Sun is gravity (huge mass), since Sun Gravity is around 28 times bigger than Earth gravity.
For the answer using a elaborated theory please refer to the monograph:
Landau L & Lifshitz E (1980) Statistical Physics, Pergamon Press
Chapter 11, section 107, equilibrium of bodies of large mass, pp. 320
Respect to Earth, our planet, it has a magnetosphere. A plasma-filled cavity formed in the flow of the solar wind during its interaction with the geomagnetic field of Earth.
Discovered experimentally in 1958 as a result of measurements, carried out on the Explorer-1 satellite (USA). The term was introduced in 1959 by the US astronomer, Prof. T. Gold. Please, refer to the magnetosphere wiki for a complete information.
The Earth's magnetic field is a protective shield that deflects most harmful radiation from the Sun, such as high-energy protons and electrons, away from the planet. It also helps to keep the atmosphere from being blown away by the solar wind, a stream of charged particles from the Sun. The magnetic field is generated by the movement of molten iron in the Earth's outer core. This movement creates an electric current, which in turn generates a magnetic field.
The Earth's magnetic field is not constant, but it has been changing slowly over time. In fact, the Earth's magnetic field has reversed itself many times in the past. The last time this happened was about 780,000 years ago.
The Earth's magnetic field is important for life on Earth because it protects us from harmful radiation and helps to keep the atmosphere from being blown away. It is also important for navigation, as it allows compasses to work.
Hydrostatic equilibrium of the Sun
The Sun is a star that is held together by its own gravity. The gravitational force of the Sun's core pulls everything in towards the center, while the outward pressure of the hot gas in the Sun's outer layers pushes everything outwards. These two forces are in balance, and this is what allows the Sun to maintain hydrostatic equilibrium.
The Sun's core is very hot and dense, and it is here that nuclear fusion occurs. This is the process by which hydrogen atoms are combined to form helium atoms, and it releases a tremendous amount of energy. This energy is what powers the Sun.
The energy from the Sun's core travels outwards through the Sun's interior until it reaches the surface. Here, it is emitted as light, heat, and other forms of radiation. This energy is what powers life on Earth.
The Sun is constantly losing energy through this process, but it is also constantly generating new energy through nuclear fusion. This is what allows the Sun to maintain its size and brightness for billions of years.
Hydrostatic equilibrium is an important concept in astrophysics, and it is what allows stars to exist. Without hydrostatic equilibrium, stars would either collapse in on themselves or explode.
Magnetism is vital for stars like our sun to form. The Earth's magnetism protects our atmosphere from harmful radiation. And cosmic magnets generate energetic high-speed particles which, on arrival at Earth, can cause random genetic mutations and hence drive evolution. Many animals, such as birds and sea turtles, rely on the Earth's natural magnetic field for navigation during migration. Exposure to artificial magnetic fields, generated by power lines or other sources, may interfere with these animals' ability to navigate, potentially causing disorientation and stranding. Generated by the motion of molten iron in Earth's core, the magnetic field protects our planet from cosmic radiation and from the charged particles emitted by our Sun. It also provides the basis for navigation with a compass. The Earth's magnetic field is powered by the solidification of the planet's liquid iron core. The cooling and crystallization of the core stirs up the surrounding liquid iron, creating powerful electric currents that generate a magnetic field stretching far out into space. Changes over time scales of a year or more mostly reflect changes in the Earth's interior, particularly the iron-rich core. Frequently, the Earth's magnetosphere is hit by solar flares causing geomagnetic storms, provoking displays of aurorae. The structure of the sun adjusts until the gravitational "pull" towards its center is just balanced by the "push" of the gas pressure outward. Fortunately, this results in a very stable state, is hydrostatic equilibrium. In fluid mechanics, hydrostatic equilibrium is the condition of a fluid or plastic solid at rest, which occurs when external forces, such as gravity, are balanced by a pressure-gradient force. Equilibrium in stars. Main-sequence stars are in equilibrium in two ways: Hydrostatic equilibrium means that the pressure of the gas inside of a star (which tries to make it expand) balances the force of gravity. A star's life is a constant struggle against the force of gravity. Gravity constantly works to try and cause the star to collapse. The star's core however is very hot which creates pressure within the gas. This pressure counteracts the force of gravity, putting the star into what is called hydrostatic equilibrium. The Earth's outer core is in a state of turbulent convection as the result of radioactive heating and chemical differentiation. This sets up a process that is a bit like a naturally occurring electrical generator, where the convective kinetic energy is converted to electrical and magnetic energy. It deflects most of the solar material sweeping towards us from our star at 1 million miles per hour or more. Without the magnetosphere, the relentless action of these solar particles could strip the Earth of its protective layers, which shield us from the Sun's ultraviolet radiation.