Once upon a time, "trial by fire" was a literal trial, with literal fire. The idea was that if an accused criminal were subjected to mortal danger, such as a fire, divine intervention would save the truly innocent. These were called trial by ordeal, and in some ways it made sense.
Of course, the system was far from foolproof; many of the trials were easily manipulated by the administering judges (or priests) to “prove” a verdict that they thought was correct. Still, some authors, such as George Mason University economist Peter Leeson, say that in a society that unflinchingly believes in the efficacy of these trials, the ordeals and ordealists would have resulted in the “correct” verdict more often than not. After all, if a person was guilty, but believed that the trials always showed the truth, they’d be unlikely to be willing to undergo them—the punishment for pleading guilty was almost always far more lenient than the punishment for being “shown” to be guilty under trial by ordeal.
There were many different ordeals used to separate the innocent from the guilty -burning, poisoning, drowning, torture- and specific procedures for each that you can read about at mental_floss. Link