Okay, so it takes three things to create a fire: fuel, oxygen, and heat (e.g., a spark or a match). If any of these three factors are missing, the fire can’t exist—so water works to extinguish a fire by eliminating these factors.
When water comes in contact with the fire, it vaporises, and this steamy cloud effectively suffocates the fire by cutting off the oxygen supply. The vaporisation also absorbs heat and thus takes the heat out of the burning, by cooling the air, smoke, and the burning material/fuel. This prevents the spreading of the fire, and lessens the intensity of the burning.
Basically, water asphyxiates a fire!