Why gold is considered an investing safe haven

When things get messy in the markets, many investors turn to gold as a safe haven. But why?