My guess would be a new power supply.
If your computer shuts down randomly, odds are good the power supply is on its last legs.
Replacing it is the way to go and will give your computer many more years of service.