Answer: Nuclear fusion and Gravitational contraction
A star is born when the material of a nebula collapses due to the gravitational force of its elements. Converting this later into the nucleus of the new star, composed of hydrogen.
Then, when this nucleus has reached sufficiently high density and temperature, it becomes helium by means of nuclear fusion (union of two light atoms), releasing energy in the process, which is the cause of the great luminosity of the star.
In other words, stars generate their own energy, in a process in which there is a balance between the gravitational pressure that compresses (contracts) matter and raises its temperature sufficiently for nuclear reactions to start, generating pressure in the opposite direction to the gravitational force by the heat produced in the reaction.
So, these nuclear reactions expand the star for most of its life, as long as this equilibrium exists.