It will have originated from something that Karl Marx wrote in 'Der achtzehnte Brumaire des Louis Bonaparte': "Hegel bemerkt irgendwo, daß alle großen weltgeschichtlichen Tatsachen und Personen sich sozusagen zweimal ereignen. Er hat vergessen, hinzuzufügen: das eine Mal als Tragödie, das andere Mal als Farce." (Spelling adjusted to today's standards)
(" Hegel notices (= remarks) somewhere that all great facts and persons of history take place twice, so to say. He forgot to add: once as a tragedy, the other time as a farce.")
The current versions I know are "Geschichte wiederholt sich - das eine Mal als Tragödie, das andere Mal als Farce."
and "In der Geschichte ereignet sich alles zweimal, einmal als Tragödie, das andere Mal als Farce."
I prefer the second ^^