The word itself appears to derive from the lines “And then,
just to show them, I'll sail to Ka-Troo / And Bring Back an It-Kutch, a
Preep and a Proo, / A Nerkle, a Nerd, and a Seersucker, too!” in the
Dr. Seuss book If I Ran the Zoo (1950). (The
spellings ‘nurd’ and ‘gnurd’ also used to be
current at MIT, where ‘nurd’ is reported from as far back as
1957; however, knurd appears to have a separate
etymology.) How it developed its mainstream meaning is unclear, but sense 1
seems to have entered mass culture in the early 1970s (there are reports
that in the mid-1960s it meant roughly “annoying misfit”
without the connotation of intelligence.
Hackers developed sense 2 in self-defense perhaps ten years later,
and some actually wear “Nerd Pride” buttons, only half as a
joke. At MIT one can find not only buttons but (what else?) pocket
protectors bearing the slogan and the MIT seal.