If I were you, I would download HWinfo and monitor the temps right before it shuts down. If the gpu or the cpu temps are showing 90+, then it is definitely shutting down because of heat. Go ahead and list the idle temps though and the temps while gaming.
There are several reasons it can start overheating randomly:
1. Check for failing fans on the cpu, gpu and the case. If any of them are failing, it could overheat.
2. The thermal paste that the manufacturers apply can dry up over time and pull away from the heatsink and processor die. This can happen on both the gpu and the cpu, and if you are not comfortable replacing them, then you should take it to a local tech.
3. The cpu or the gpu could be failing, which can sometimes manifest as an inability to regulate temperature.
My guess is that it is 1 or 2. How old is the pc?