Controlled burns are used ahead of a forest fire. The ground is burned in a line of small fires before the out of control fire arrives. This uses up all the fuel for the other fire, and will hopefully stop at this burn line.
The literal meaning of fighting fire with fire is when they use small, controlled fires to burn away leaves, sticks and other flammable things that accumulate on the forest floor. Once all of these things are gone there's less fuel for real forest fires and they don't get big enough to burn the trees themselves.
The colloquialism has come to mean any time you fight something with a similar thing. Someone is being a jerk, so you act like a jerk back to them, for example.
But if the wind is strong and it is a large fire, sometimes a spark or burning bit will jump the line.
This analogy is used for lots of other "fighting like with like" ideas.