“Famous last words” was originally used to refer to the actual dying words of prominent people. That is, it was a literal reference to the well-known last words of some famous person.
Only in the 20th century did the phrase begin being used figuratively – when no one was actually dying. It was probably brought into the realm of sarcasm by such well-known last words as “They couldn’t hit an elephant from this distance” – an actual statement made by U.S. Civil War General John Sedgwick immediately prior to his being shot dead by a sniper.
It was initially used in a figurative sense to suggest in jest that something that had been said might cause offence and the person taking offence might respond violently; for example:
A. “I think I’ll ask Mike Tyson if he’s always had that lisp”.
B. “Famous last words!”.
The first instances of this form were printed in a series of newspaper cartoons in the 1920s/30s. This early example is from The Milwaukee Sentinel July, 1928.
The phrase was later extended to refer to more general potentially lethal situations, as in this piece from Shell Aviation News, 1948:
Leopoldville is easy to find because you cannot miss the Congo River. (Famous last words!)
It is now used widely and in reference to situations where the outcome might be bad, but in a minor rather than lethal way; for example:
A. “We won’t miss the train. Mike’s never late”.
B. “Famous last words!”.
A more recent version of the comical but rather tragic actual last words to rival General Sedgwick’s are the final words of Terry Kath, a founding member of the rock band Chicago, He said, “Don’t worry, it’s not loaded.” just before accidentally shooting himself in the head with a 9mm. pistol.
See also: the famous last words of famous people.