After it shuts down and you get it running again, check Settings/General/Battery. Tap the graph to get the second graph. If you see a sudden drop to 0, the battery is throwing a dendrite (a factory defect that's unfortunately not covered by warranty - the battery is only about $10, but I strongly recommend that you let a repair shop replace it, or you can cause more damage than it already has [like ripped wires]).
In the future, start looking for an outlet when the battery gets down to 50%, so that you'll be charging it before it drops below 40%. Regularly discharging to 20% is much too low to get any kind of longevity from the battery.