It is gravity that gathers matter in interstellar clouds and forms stars. It is the balance between gravity and the outward radiation pressure formed by nuclear fusion reaction that keeps the stability of the star. It is also gravity that causes the stars to collapse.
In stars, gravity is inward, and radiation pressure formed by nuclear fusion reaction is outward. Gravity has been pulling the matter in the star towards the center, while radiation pressure has been pushing the matter out of the star. When the two forces are equal, the star will be stable, just like the sun now.
When the star evolves to the later stage, the raw materials of internal nuclear fusion reaction (early hydrogen, late helium, and even carbon, nitrogen, hydrogen, oxygen, sulfur and other elements) are insufficient, and the intensity of nuclear fusion reaction decreases, and the reaction may even stop. The outward radiation pressure used to compete with gravity decreases or even disappears, and gravity will regain the upper hand and pull the matter in the star inward. The result is the collapse of stars. Therefore, the collapse of stars is also called "gravitational collapse".