I have read many stories of great Rabbis, historically and in today's times, who have given people medical advice which was in direct contradiction to the advice given by expert medical professionals. Often times these stories are situations of life or death decisions where the doctor is saying that if the advice of the Rabbi is followed the patient will likely die. The stories all turn out with the patient listening to the Rabbi over the doctor and everything turns out well for the patient. It is my understanding that in regards to a medical question the halacha is that a person should (must?) follow the advice of medical experts and not rely on a miracle. I would like to understand what basis, if any are Rabbis allowed to give such advice and if the patient is allowed to follow the advice, why?
Note I am not asking about a situation where a Rabbi has as much medical knowledge (or more) than the experts and is therefore giving his advice in the capacity as a medical expert