Serious food poisoning will kill or permanently maim you. Less serious food poisoning and you’ll just wish it would kill you!
Not all food poisoning is bacterial - there are some fascinating viral, amoeboid, flagellate and fungal types, but this is likely to be a long post just to cover some of the basics of bacterial food poisoning raised by previous posters.
Toxins:
Bacterial toxins can be heat-labile (destroyed by heat) or heat-stable (not destroyed by heat). Some of the more ingenious food poisoning bugs produce both! Bugs don’t have to be dead to liberate toxins. Some food poisoning bugs are infectious (ie you ingest a few bugs, they colonise you, multiply, and produce various toxins post infection). Others are intoxicating. They multiply in food and produce toxins which you ingest and become ill from without the bugs taking up residence in you at all.
Food types:
The need to cool food rapidly is not limited to protein foods. You can get cereal based food poisoning as well from ill-cooled food. You can also get dairy based, but I’m not aware of rapid cooling as a significant issue there.
Sporeformers:
Bacteria other than sporeformers can be destroyed by boiling. If the food is cooked for long and hot enough, all the non-sporeformers initially in the food will be killed. Some of the spores from the sporeformers will not. Leave the food at room temperature for a few hours in the right conditions and the sporeformers will generate.
You can pretty well divvy up the sporeformers into aerobic (Bacillus) and anaerobic (Clostridium). Not all food poisoning sporeformers require anaerobic conditions. It is theoretically possible for some strains of Clost to germinate under locally reducing (rather than strictly anaerobic) conditions, but it isn’t the most likely situation. What is a problem are the aerobic sporeformers, particularly Bacillus cereus. It can produce both heat-labile and heat-stable toxins, and has been implicated in outbreaks of food poisoning in a range of cereal-related products such as fried rice, meat pies and crumpets. (In fact, fried rice is how it was identified as a food poisoning organism. Chinese restaurants used to be closed on Mondays. Some would boil the rice last thing on Sunday/early Monday for Tuesday’s fried rice. It would be left to cool still covered, still in the cooking containers, on the bench. The spores would germinate, mulitply to a sufficient level to produce toxins, the heat stable toxins would survive the frying process and on Wednesdays there would be a bunch of people calling in sick.)
Where do the sporeformers come from? By and large, from the soil. Thus to the raw food, to the supermarket and to you. Spices and grains, unless treated, often have a high spore load.
Boiling:
Sure, boiling will knock off the nonsporeformers, and as long as the container in which the boiling was done is airtight, the food won’t have any nonsporeformers. My pots sure aren’t airtight, and I’m betting yours aren’t either unless you are doing home canning. So as the food cools down, air is drawn into the pot, and guess what comes with it? Yup, bacteria. Sporeformers and non sporeformers alike.
Cooling:
If the food is particularly dense, or the container particularly large, it can remain a nice comfy bug warm temperature in the middle of the food for a loooooong time. Lots of tme for bugs to multiply and produce toxins.
My advice: You don’t have to whisk the pot from the flame to the fridge. But as soon as it is just cool enough to pick up with your hands put it in the fridge. And throw leftovers out after 3 days in the fridge.
Frankly, once you’ve experienced rectal tenesmus (straining to evert the bowel - one of the symptoms of B. cereus food poisoning, and (oh joy!)it can be simultaneous with vomiting) you’ll have no sympathy with the thought that it’s important to avoid straining the fridge rather than you!