What is the difference between 防ぐ and 予防する ?
To me both of them seem to mean "to prevent".
A Japanese person once explained to me how they are different but unfortunately I don't remember.
Similar question: What is the difference between 防止 and 予防?
予防する ＝ 予め防ぐ. 予 of 予防する means 予め（あらかじめ, in advance）. So 予防する is to prevent in advance. Yes, the meaning of 防ぐ(prevent) itself includes the concept 'in advance', but 予防する emphasizes the meaning.
我々は火の手が広まらないように防いだ.(We prevented the fire from spreading. ) In this case, we don't say 予防した, because the fire actually happened already.
There's a little more nuance to it than one being 'in advance,' I think. 予防 is used in limited situations to refer to prevention of certain medical or natural disasters, usually referring to preventive measures taken to protect against fire, or something like vaccinations to prevent illness. If you check this dictionary entry for 予防 you get a single, specific answer:
To translate, it refers to advance prevention, as we see in 予, but it specifically refers to things like illness and natural disasters.
The definitions for 防ぐ on the other hand are rather varied and have much more of a physical nuance of preventing something on the outside from getting inside something, much more in the sense of defense rather than in prevention. Indeed, prevention can be seen as an advance defense, but 防ぐ is more about the act of keeping something out rather than the action as a meditated action in regard to an anticipated event.
To steal a few examples from that dictionary entry: 「敵の猛攻を―・ぐ」「外敵の侵入を―・ぐ」「冷たい北風を―・ぐ」「西日を―・ぐ」
Apparently one of the definitions allows for a similar meaning to 予防, as in here:
But the dictionary itself defines it as 防止 rather than 予防, which is basically the difference between "halt/stop from happening" and "take early defensive action."
Sorry to be perhaps a little obvious, but isn't the difference that one is a verb and the other is a noun made into a verb, where the difference in grammatical construct carries its own nuance?
In English we can do a similar thing with the root word "prevent". We can either use it as a noun, "a prevention (against...)", or we can use it as a verb, "to prevent (something...)".
Bottom line is that I think they do mean the same thing, the difference only lies in the nuance that exists any time you choose between a verb or noun-made-verb.