Auto shutoff after a few seconds makes me think of a PSU failure or motherboard failure. Leaning more towards motherboard failure since it sounds like the motherboard is generating the power off signal, not the PSU turning off PWR_OK signal. Could be power phasing fault, fault with CPU, fault with RAM, or even a number of other motherboard related faults. Could also be overheating of the CPU (CPU fan failure) but that tends to last longer before shutdown.
Can't be more specific without more details. Try looking at the motherboard to see if there are any swelling, leaking or blown capacitors. Telling us what type of PSU and motherboard might help too, as well as knowing how it was used up to now and for how long these issues have persisted.