early 13c. (intransitive), "waver, vacillate, lack steadfastness," probably from a Scandinavian source (compare Old Norse vagga "a cradle," Danish vugge "rock a cradle," Old Swedish wagga "fluctuate, rock" a cradle), and in part from Old English wagian "move backwards and forwards;" all from Proto-Germanic *wag- (source also of Old High German weggen, Gothic wagjan "to wag"), probably from PIE root *wegh- "to go, move, transport in a vehicle."
Transitive meaning "move (something) back and forth or up and down" is from c. 1300; of dogs and their tails from mid-15c.: "and whanne they [hounds] see the hure maystre they wol make him cheere and wagge hur tayles upon him." [Edward, Duke of York, "The Master of Game," 1456]. Related: Wagged; wagging. Wag-at-the-wall (1825) was an old name for a hanging clock with pendulum and weights exposed.