The one-liner came from London comic Dan Antopolski, 36, who is known for his surreal stand-up routines.
A panel of nine comedy critics sifted through more than 3,600 minutes of material to find the winner of the Dave Award for the Funniest Joke of the Fringe.
They each had a pool of around 7,200 different jokes to choose from, based on estimates of the average comedian telling two jokes per minute, organisers said.
Shortlisted gags were put up for the public vote, with more than 3,000 comedy fans choosing the funniest.
With nearly 18% of votes, Antopolski took top spot and walked away with a trophy from TV channel Dave and a £1,000 (€1,150) cash prize.
The joke was taken from the Perrier Award-nominee’s show Silent But Deadly.
Antopolski said: “Although I have won things before at the Fringe, this definitely means the most to me, and that it should unite my loves of hedgehogs, comedy and Dave makes this prize very special.”
TV star Denise van Outen, who made her debut in a new one-woman musical comedy show called Blondes, was named by judges as telling what they felt was one of the worst gags.
The joke went: “A brunette, a red-head and a blonde break out of Holloway Prison.
“They hide in a barn from the police and get into some sacks.
“The police come in and feel the sack with the brunette in it – she goes ‘miaow’!
“They go on to feel the sack with the red-head in it – she goes ‘woof!’ Finally they feel the sack with the blonde in it. The blonde shouts: potatoes!”
Another offering that did not go down well with the critics was from Alistair McGowan, which went: “I’ve just split up from my girlfriend, which is a shame, because it was a long-standing arrangement. Perhaps if we’d sat down a bit more...”
The Edinburgh Festival Fringe ends on August 31.