What is the origin of "head off" in the sense "to prevent"?
Solution 1:
To head off (v.) seems to come from "A heading" - a direction of travel, which became a verb:
OED
†3. Hunting. With reference to a hunted (or occasionally hunting) animal: the action of changing direction suddenly and sharply while running; doubling. Also: an instance of this. Cf. head n.1 47. Obsolete.
1607 E. Topsell Hist. Foure-footed Beastes 152 The nature of this Hare is, sometimes to leape and make headings, sometime to tread softly.
Which then was used in a nautical context as a verb and a noun:
a. intransitive. To move forwards in a specified direction or towards a particular place or thing. Later also more generally: to go, make one's way. Also transitive: to follow (a course, way, etc.) in a specified direction.
1817 A. Delano Narr. Voy. & Trav. Northern & Southern Hemispheres xxiv. 468 I was just heading for the land, when..I saw one of my faithful sailors..making towards me with all possible exertion.
OED has the entry:
to head off
- transitive.
a. To move ahead of so as to intercept, or so as to obstruct and cause to turn back or aside.
1825 E. Mackenzie Hist. View Northumberland (ed. 2) II. 144 The fox took towards Rotherbury Forest... Here it appears he was headed off.
Which then gave rise to your "to prevent [something from happening]
b. To stop (a person or thing) from accomplishing some purpose, goal, task, etc.; (also) to anticipate and prevent; to avert.
1866 Missionary Mag. July 232 The Pastors..have failed..to foresee and head off disaster.
2008 B. G. Ramcharan Preventative Diplomacy at UN 1 Wherever feasible, everything possible should be done to head off a conflict or disaster.
Solution 2:
According to the AHD the phrasal verb head off dates back to mid 19th century:
Block the progress or completion of; also, intercept. For example, They worked round the clock to head off the flu epidemic, or Try to head him off before he gets home. [First half of 1800s]
This expression gave rise to head someone off at the pass, which in Western films meant "to block someone at a mountain pass." It then became a general colloquialism for intercepting someone, as in Jim is going to the boss's office-let's head him off at the pass.