1809, originally nautical, "in a state of collision or entanglement," from a- (1) + foul (adj.). From 1833 in general sense of "in violent or hostile conflict," mainly in phrases such as run afoul of.
Entries linking to afoul
a- 1
prefix or inseparable particle, a conglomerate of various Germanic and Latin elements.
In words derived from Old English, it commonly represents Old English an "on, in, into" (see on (prep.)), as in alive, above, asleep, aback, abroad, afoot, ashore, ahead, abed, aside, obsolete arank "in rank and file," etc., forming adjectives and adverbs from nouns, with the notion "in, at; engaged in." In this use it is identical to a (2).
It also can represent Middle English of (prep.) "off, from," as in anew, afresh, akin, abreast. Or it can be a reduced form of the Old English past participle prefix ge-, as in aware.
Or it can be the Old English intensive a-, originally ar- (cognate with German er- and probably implying originally "motion away from"), as in abide, arise, awake, ashamed, marking a verb as momentary, a single event. Such words sometimes were refashioned in early modern English as though the prefix were Latin (accursed, allay, affright are examples).
In words from Romanic languages, often it represents reduced forms of Latin ad "to, toward; for" (see ad-), or ab "from, away, off" (see ab-); both of which by about 7c. had been reduced to a in the ancestor of Old French. In a few cases it represents Latin ex.
[I]t naturally happened that all these a- prefixes were at length confusedly lumped together in idea, and the resultant a- looked upon as vaguely intensive, rhetorical, euphonic, or even archaic, and wholly otiose. [OED]
foul adj.
Old English ful "rotten, unclean, vile, corrupt, offensive to the senses," from Proto-Germanic *fulaz (source also of Old Saxon and Old Frisian ful, Middle Dutch voul, Dutch vuil, Old High German fül, German faul, Gothic füls), from PIE *pu- (2) "to rot, decay," perhaps from the sound made in reaction to smelling something bad (see pus).
Old English ful occasionally meant "ugly" (as contrasted with fæger (adj.), modern fair (adj.)), and this sense became frequent in Middle English. The cognate in Swedish is the usual word for "ugly." Of weather from mid-14c. In the sporting sense of "irregular, unfair, contrary to established rule or practice" it is first attested 1797, though foul play is recorded from mid-15c. Baseball sense of "out of play" attested by 1860.