Origin of hat trick
1879, originally from cricket, "taking three wickets on three consecutive deliveries;" extended to other sports (especially ice hockey) c.1909. Allegedly because it entitled the bowler to receive a hat from his club commemorating the feat (or entitled him to pass the hat for a cash collection), but also influenced by the image of a conjurer pulling things from his hat (attested by 1876). The term was used earlier for a different sort of magic trick:
Place a glass of liquor on the table, put a hat over it, and say, "I will engage to drink every drop of that liquor, and yet I'll not touch the hat." You then get under the table; and after giving three knocks, you make a noise with your mouth, as if you were swallowing the liquor. Then, getting from under the table, say "Now, gentlemen, be pleased to look." Some one, eager to see if you have drunk the liquor, will raise the hat; when you instantly take the glass and swallow the contents, saying, "Gentlemen I have fulfilled my promise: you are all witnesses that I did not touch the hat." ["Wit and Wisdom," London, 1860]
In some sports, such as ice hockey, three goals by one player in a single game: “Lemieux scores for the third time tonight; he finally has the hat trick he's been looking for all season.”
An extremely clever or adroit maneuver, as in It looked as though the party was going to achieve a hat trick in this election. The term originated in cricket, where it refers to three wickets taken by a bowler in three consecutive balls, traditionally rewarded with the presentation of a hat. It later was transferred to ice hockey, soccer, and baseball, where it denotes three consecutive successes (goals, hits), and then to more general use.