Can you turn the phone on again after it has powered off without connecting it to the charger? If you do, then there's something wrong with either the phone's internals or a software glitch. If not, then it's likely to be your battery.
To test the battery you could, if possible, try to use the same battery with the same charge it has left after powering off, on a different S4. That way you rule out the phone as a possibility.
What you could also try is 'resetting' your battery... charge to 100% and then let it discharge until it cannot turn on any longer. Then re-charge to 100% to force the battery to re-calibrate.