https://www.gsmarena.com/samsung_i9500_galaxy_s4-5125.php
Is the battery in your phone the original battery it came with or have you replaced it at some point? I wouldn't be surprised if your problems are tied to the battery starting to fail. (... and don't be disappointed, it's apparently been doing its job for quite a while as far as smartphone batteries go) Given the S4 was first released in 2013 and you're estimating using it for four years or so, if you bought it new that also means it sat completely idle in storage for a couple of years, another factor that ages a battery prematurely.
Your model has a user-replaceable battery and looking online they're relatively cheap so that might be something to try. One caveat is most after-market batteries for dated phones will typically be pretty dated themselves, there's little money for battery manufacturers to make and store them. So perhaps instead of putting any money into your S4, even if it's not that much, it might be more prudent to just start thinking of getting a new or newer phone.
In any case since it is acting up be sure you have your saved data safely backed up, just in case there's something more serious than just the battery.
https://www.samsung.com/us/smart-switch/