Why where thy wrong? Simple, for once the media was extremely biased for Clinton, wrote her up as much as they could in the hope that people, that where against her would simply give up and so make it a self fulfilling prophecy. For example they published polls, that only asked people that already had voted in previous elections, and these where mostly Clinton, Trump got most of his votes from people that didn't vote before, regardless of reason.
They also overestimate their power and the power of the establishment and underestimate the power of the internet, in their world they still have ultimate power, to decide who wins and who not, but the internet works on different rules and remembers things, like Clinton's history, instead the network community brings these up again and inform people.
In another part they simply thought that the "blue dogs" (Democratic voters that always voted Democrats), would all vote for Hillary (as well as she herself thought that) but after what she pulled of against Sanders many of them just didn't vote at all or voted Trump just to pay Hillary back.
In the end the establishment tripped over its own arrogance, in the same way the British did with "Brexit"