This is a "quill stem" and uses a "wedge" or an "expander" to press against the inside of the steerer tube (the top part of the fork.)
When fitted correctly, the quill stem sits in the fork and is held in place because the grey part at the bottom is pulled up by a long thread and it is pressing against the inside of the fork. Here the thread that pulls up the bottom piece must have been come loose or broken.
If this happens quickly it is dangerous because you no longer can steer the bike with the handle bar and quite likely will crash. If it happens slowly you will find that front wheel and handle bar are no longer properly aligned and this would trigger you to inspect it.
I can't answer how likely a fatal accident would have been but count yourself lucky to have noticed the problem.
