In its original sense, a shaggy dog story is an extremely long-winded tale (traditionally about a talking dog, but potentially on any subject) featuring extensive narration of typically irrelevant incidents, that usually results in a pointless or absurd punchline.
"Shaggy dog story" has come to also mean a joke where a pun is finally achieved after a long (and ideally tedious) exposition.
- The Symphony Orchestra was playing a concert in the park and was in the middle of Beethoven's 9th Symphony. The basses, in the back of the orchestra, decided they had a few minutes to spare before being required to play anything, so they ran across the street to the pub for a few beers. As it was quite a windy day, before they left for the pub they found some string to wrap around their music stands to secure their music while they were gone. Once at the tavern, they could hear the music and keep up with the progress of the piece.
- Rather than leisurely enjoyment of one beer, the basses decided they would actually prefer some hasty enjoyment of multiple beers. After finishing their fourth or fifth beverage they decided that they had better hurry, because the last movement of the ninth symphony was underway. They stumbled back onto the bandstand, but in their inebriated state they found they were fumbling with the string, trying to get it loose, but not having much success. The conductor saw what was happening and instantly sized up the situation: it was the bottom of the ninth, the score was tied and the basses were loaded.
- (Don't get it? "It was the bottom of the ninth, the score was tied and the bases were loaded" is a cliched line from baseball. "Loaded" is also slang for "drunk" in many English-speaking countries.)