"long, slender rod," originally "staff or pole forming the body of a spear or lance; spear-shaft," also, perhaps by synecdoche, "spear;" Middle English shafte, from Old English sceaft from Proto-Germanic *skaftaz (source also of Old Norse skapt, Old Saxon skaft, Old High German scaft, German schaft, Dutch schacht, not found in Gothic).
OED suggests this might be explained as a Germanic passive past participle of PIE root *(s)kep- "to cut, to scrape" (source of Old English scafan "to shave, scrape, polish") on notion of "tree branch stripped of its bark." But compare Latin scapus "shaft, stem, shank," Greek skeptron "a staff" (see scepter) which appear to be cognates.
Extended generally to any body of long, cylindrical shape; the meaning "beam or ray" (of light, etc.) is attested from c. 1300; that of "arrow" (especially a long one, used with a long bow) is from c. 1400; that of "a long, straight handle of a tool or utensil" from 1520s. The mechanical sense "long rotating rod for transmission of motive power in a machine" is from 1680s.
The vulgar slang meaning "penis" is recorded by 1719 on notion of "columnar part" (late 14c.); hence probably modern slang shaft (v.) and the related noun meaning "act of unfair treatment" (1959), though some early sources insist this is from the notion of a wound.