As stars age, they produce energy by fusion - fusing hydrogen to helium, and then helium to heavier elements (carbon, oxygen,… iron)
This “enriched” material is ejected back into interstellar space as the star is dying