I don't know if this will work in all situations, but when dd is flipping out when (for example) she can't get a math problem right that she thinks she should be able to do, I try to hug her, or hold her hand or at least touch some part of her body and then repeat the mantra "everything's going to be okay. Everything's going to be okay". Over and over; she fought it a little at first but now it works, and the more I have used it over the years, the faster it works. I think it has a subtle way of reminding her that she has "been there" before (facing what seems to be an insurmountable challenge/problem) and then coming back to it 15 minutes later and getting it. Actually, since we have talked a lot about that once the outburst was over and resolved ("remember that other time you thought you'd never be able to xyz, and then it came easy?") I think we've linked the mantra to the "success".
IDK, works for us.