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:
(3)悪いことが起ころうとするのを、あらかじめ手段を講じてくいとめる。防止する。
「病害虫の発生を―・ぐ」「事故を未然に―・ぐ」
But the dictionary itself defines it as 防止 rather than 予防, which is basically the difference between "halt/stop from happening" and "take early defensive action."