Derives from the episode of Mythbusters:
A saying that describes how close something was to happening. Usually uttered when in relief that something tragic did not occur.
The saying has it's origins in the Mythbusters episode where they rigged a dummy up to urinate on the third rail, of a railway track, which would subsequently give a lethal amount of electricity.
Jon: Aw mate imagine if you went out with Cersei.
Davos: I almost did.
Jon: No fucking way.
Davos: Yea, but she didn't like older guys, Christ, can you imagine? I nearly pissed on the third.