early 15c., "a cheat, a mean ruse," from Old North French trique "trick, deceit, treachery, cheating," from trikier "to deceive, to cheat," variant of Old French trichier "to cheat, trick, deceive," of uncertain origin, probably from Vulgar Latin *triccare, from Latin tricari "be evasive, shuffle," from tricæ "trifles, nonsense, a tangle of difficulties," of unknown origin.
Meaning "a roguish prank" is recorded from 1580s; sense of "the art of doing something" is first attested 1610s. Meaning "prostitute's client" is first attested 1915; earlier it was U.S. slang for "a robbery" (1865).
To do the trick "accomplish one's purpose" is from 1812; to miss a trick "fail to take advantage of opportunity" is from 1889; from 1872 in reference to playing the card-game of whist, which might be the original literal sense. Trick-or-treat as a children's Halloween pastime is recorded from 1927 in Canada. Trick question is from 1907.