Geek is actually a very old word. It is a variant of geck, a term of Low German/Dutch origin that dates in English to 1511. It means a fool, simpleton, or dupe. Geck is even used by Shakespeare in Twelfth Night.
"Why haue you suffer'd me to be imprison'd. And made the most notorious gecke and gull That ere inuention plaid on?"
The geek spelling is an American variation, even though Shakespeare uses the spelling geeke in Cymbeline V.iv., but this is probably just a misspelling. Geek first appears (outside the single Shakespearean usage) in 1876 America. American usage adds the connotation of offensive or undesirable to the original foolish and stupid sense. The Carnival sideshow sense appears in 1928.