If you can tell it's definitely going to die in like 5 minutes, you can throw it in a bucket of ice water, then throw it back in your tank. (like a jolt. Kind of what they do to us if we stop breathing)
Only keep it in the ice for a very short amount of time. (10 seconds or less)
I would use this only as a last resort. My neighbor brought back a goldfish this way, luckily, I've only had to use it once.
DO NOT do this unless your certain it will die other wise.