There are lots of reasons for the surprising election result. This article provides one good reason for the result. The electorate believed that Clinton was better qualified for the presidency than Trump but it was clear that Trump was regarded as the change agent in the election. That was pretty clear from the primary campaigns. Trump ran his campaign against the GOP establishment by presenting himself as the only Republican who was a change agent. That enabled him to defeat many better qualified candidates who were favored by the Republican leadership. Clinton was opposed by Bernie Sanders who did a much better in the primaries than anyone expected. He was the change agent in the Democratic campaign. Exit interviews from the presidential election indicated that 40% of the electorate said their top priority was to elect a change agent. Trump won 83% of their votes. Clinton's campaign chose to attack Trump's fitness for the job. Ordinarily that is a good strategy. It seemed like a great strategy after so much negative information about Trump surfaced in the presidential election. It did not work this time.
We should not forget, however, that Clinton would have won the election if she had won Wisconsin, Michigan and Pennsylvania. They were very close races that Trump won by one one tenth of 1%. Moreover, third party candidates may have helped to create that slim margin for Trump. If all of Jill Stein's votes had gone to Clinton she would have won Wisconsin and Michigan. She was running on a very liberal ticket; those who voted for her would not have gone to Trump. If Stein's votes in Pennsylvania had gone to Clinton, along with 20% more of the other third party candidates votes, Clinton would have won Pennsylvania as well.