From Etymonline: doggone 1851, Amer.Eng., a "fantastic perversion of god-damned" [Weekley].
But Mencken favors the theory that it is "a blend form of dog on it; in fact it is still often used with it following.
It is thus a brother to the old English phrase, "a pox upon it," but is considerably more decorous."