1769, "pin passed through the eye of a rope, strap, or bolt to hold it in place," a nautical word of uncertain origin, perhaps a frequentative form of tog "tug." As a kind of wall fastener it is recorded from 1934. Toggle bolt is from 1794; toggle switch, the up-and-down sort, first attested 1938. In computing by 1979, in reference to a key which alternates the function between on and off when struck.
1836, "make secure with a toggle," from toggle (n.). Meaning "alternate back and forth between opposite actions" is by 1982. Related: Toggled; toggling.