To keep your food bacteria safe (it is not 100% possible) keep in mind that the food temperature danger zone is 5C to 60C or 41F to 140F. So, if you keep food out of this temperature range, you are preventing bacteria from multiplying and therefore safer to consume.
This in no way means that you transfer the food immediately from the stove to the fridge; you should let it cool to room temperature first, however cooling time should not exceed 2 hours. TIP: To help speed up the cooling process, divide the food into smaller portions.