2 days before the election my mother asked me who was going to win, and I hesitated a bit and said probably Hillary but it was going to be close.
Trump had enthusiasm. It's always hard to win a 3rd straight term for a single party (though O avoided scandal and the economy was pretty decent). Clinton was probably the most qualified candidate since Monroe, yet had been a GOP punching bag for decades. The last minute FBI meddling was worrisome. And a lot of folks weren't ready to vote for a female leader.
To add to that, Clinton failed to shore up her Midwest base, despite Trump saying that was his path to victory. Instead doing last week rallies in Arizona. Clinton's strength was always supposed to be her ground game, not campaigning, but it didn't pan out and Trump's use of twitter trumped whatever traditional knock on doors approach Clinton had.
In general, I'm surprised anyone would vote for a blowhard ignoramus such as Trump. But he successfully demagogued a few issues: anti-immigration, anti-free trade, anti-war, Clinton corruption (lock her up .. for using an email server) and weaponized twitter quite well.
Also, GOP obstructionism ultimately paid off. They limited what Obama could accomplish, slowed down economic growth under O, and motivated their base by stealing a Supreme Court seat. If O was able to get more done, had the economy growing faster, and added a Lefty to the SCOTUS, there would have been more enthusiasm for the Dems and Hillary, especially among independents.
Lastly Trump got away with misrepresenting himself as a moderate in some areas, saying he'd get rid of O-care and replace it with better, wouldn't touch SS and Medicare, while tossing out a few other moderate bromides he never intended.