c.1300, foilen "to spoil a trace or scent by running over it," irregularly from Old French fouler "trample," from Vulgar Latin *fullare "to clean cloth" (by treading on it), from Latin fullo "one who cleans cloth, fuller," of unknown origin.
Hence, "to overthrow, defeat" (1540s). Sense of "frustrate the efforts of" first recorded 1560s. Related: Foiled; foiling. Foiled again! as a cry of defeat and dismay is from at least 1847.