Without actually having the phone in hand to test things, I can only make an educated guess, but that would be a bad battery. At about the 30% discharge point it's forming a short (called a dendrite), which does 2 things - it causes the phone to turn off and it burns the short out, so when you turn the phone back on it works.
If you have a spare battery, another S4, a friend with an S4, etc., try another battery and if it gets past the 30% point (say discharged down to 60% or 50%), that's the problem. It's actually a manufacturing defect, so it should be covered under warranty, but considering the price of a good quality replacement battery, it's probably not worth the hassle of trying to get them to cover it. (Batteries are consumables, if you mistreat a battery it can go bad in as little as a few months, batteries aren't covered under warranty ... they have a book full of excuses why "manufacturing defect" doesn't include a manufacturing defect in the battery, and a dendrite forms if there's dirt in the battery that gets in there during manufacturing.)
An Anker battery is $15. A pair of them and a charger (that will charge a battery out of the phone at the same time it's charging the one in the phone) go for $24 ($27 if you need NFC). Having a spare in your pocket (have it in a plastic bag or envelope of some kind - keys shorting a battery with that much discharge capability will hurt when the melted key drips down your leg) is handy if you use a lot of battery, and it helps to keep the battery lasting longer. (The longest battery lifespan comes if you charge the battery around the 40%-60% discharge point.)