The word “shiver” originally referred to a small piece, fragment, or splinter of something, or to the act of breaking something into many small pieces. Hence, “shiver my/me timbers” refers to the splintering of wooden ships upon rough seas.
The “splinter” sense of “shiver” arose c. 1200 as both a noun and a verb, likely related to Middle Low German schever schiver, also meaning “splinter,” from the Old High German scivero, from Proto-Germanic skif- “split.”
You’ll notice “shiver’s” relation to the contemporary word “shiv,” an often-makeshift razor or knife used as a weapon.
The trembly sense of “shiver” possibly comes from an entirely different origin. Arising around 1400 as an alteration of chiveren (“shake”), it may come from the Old English *ceafl*, meaning “jaw,” suggesting chattering teeth.
“Shiver me/my timbers” is a fictional declaration that likely arose after the Golden Age of Pirates (1650 – 1730).
Although the Oxford English Dictionary says the expression “shiver my timbers” probably first appeared in a published work by Frederick Marryat called Jacob Faithful (1835), the phrase actually appeared in print as early as 1795, in a serial publication called “Tomahawk, or Censor General”… In the words of the “old sailor”: “Peace? Shiver my timbers! what a noise ye make – ye seem to be fonder of peace than ye be of quiet.”
Naturally, the phrase was widely popularized by Long John Silver in Robert Louis Stevenson’s Treasure Island.
“My timbers!” alone, however, was supposedly an actual nautical oath that was euphemistic in nature, as so many idioms are.
Edit: Clarity, better spacing.