The Laurel and Hardy charachter Jimmy Finlayson said damn alot in the scripts of Laurel and Hardy episodes and movies. However, when the Lauel and Hardy films and TV show were made, damn was considered a bad word. So, the word was changed to D'ooooooh, a made up word.

The Simpsons

When Matt Greoning, a cartoonist, created the TV show The Simpsons he needed a word for the charachter Homer to say whenever he got angry. He watched some old Laurel and Hardy videos, and found the word D'ooooooh. He brought the rights to the word and than shortened it to D'oh.