It’s close because of the electoral college, which is a stupid and anti-democratic system, as the US constitution itself is mostly anti-democratic.
But the other reason it’s so close, in my view, is that a good portion of the electorate’s lives are crappy, which makes them angry — and they look for reasons and someone to blame. They want explanations and to make sense of the world, as we all do. The media fill that role now, where family friends and religion once did, and cater messages to these people, depending on where they live and what their interests are and how they get their information (radio? TV? Newspaper?).
So there’s huge gaps between women and men, rural and urban people, college educated vs not, etc. The left demonizes Trump (although they have a much better case for doing so), and the right demonizes “liberals” (and do it much more effectively). Both are devils to the other side.
Since the advent of social media, distrust in literally everything and anything that doesn’t conform with what your preferred information pipeline is telling you has become rampant. Thus Trump can say almost anything — even trying to overturn an election and saying he won even when he lost — and many millions will go along with it, or shrug it off.
If CNN says he’s a threat to democracy or whatever, or if there’s reports about some crazy thing he said, it’ll be ignored— because those sources have been undermined and discredited in their minds (“fake news,” “witch hunt,” etc), mostly by Trump himself.
If the Democratic Party offered something real and started talking to working people, they’d break through a lot of this stuff — as Bernie did. But since they’re also a party of corporate America, there’s little chance of that.