That which sets off something to advantage. The allusion is to the metallic leaf used by jewellers to set off precious stones. (French, feuille; Latin, folium; Greek, phullon, a leaf.)
“Hector, as a foil to set him off.”
I'll be your foil, Laertes. In mine ignorance Your skill shall, like a star i' the darkest night, Stick flery off indeed.
“If I be foiled, there is but one ashamod who never was gracious.” —
Source: Dictionary of Phrase and Fable, E. Cobham Brewer, 1894
More on Foil from Infoplease: